Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary(带权并查集)

libfranka---joint_impendence_control例程分析 joint_impedance_control.cpp例程分析 部分内容来自链接,我个人以初学者的角度对代码进行了更加细致的解释。 核心部分: // Set and initialize trajectory parameters. const double radius = 0.05; const double vel_max = 0.25; const double acceleration_time = 2.0; const double run_time = 20.0; d 阅读详情

D. Mahmoud and a Dictionary
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discovers a new relation between two words.

He know that if two words have a relation between them, then each of them has relations with the words that has relations with the other. For example, if like means love and love is the opposite of hate, then like is also the opposite of hate. One more example: if love is the opposite of hate and hate is the opposite of like, then love means like, and so on.

Sometimes Mahmoud discovers a wrong relation. A wrong relation is a relation that makes two words equal and opposite at the same time. For example if he knows that love means like and like is the opposite of hate, and then he figures out that hate means like, the last relation is absolutely wrong because it makes hate and like opposite and have the same meaning at the same time.

After Mahmoud figured out many relations, he was worried that some of them were wrong so that they will make other relations also wrong, so he decided to tell every relation he figured out to his coder friend Ehab and for every relation he wanted to know is it correct or wrong, basing on the previously discovered relations. If it is wrong he ignores it, and doesn't check with following relations.

After adding all relations, Mahmoud asked Ehab about relations between some words based on the information he had given to him. Ehab is busy making a Codeforces round so he asked you for help.

Input

The first line of input contains three integers n, m and q (2 ≤ n ≤ 105, 1 ≤ m, q ≤ 105) where n is the number of words in the dictionary, mis the number of relations Mahmoud figured out and q is the number of questions Mahmoud asked after telling all relations.

The second line contains n distinct words a1, a2, ..., an consisting of small English letters with length not exceeding 20, which are the words in the dictionary.

Then m lines follow, each of them contains an integer t (1 ≤ t ≤ 2) followed by two different words xi and yi which has appeared in the dictionary words. If t = 1, that means xi has a synonymy relation with yi, otherwise xi has an antonymy relation with yi.

Then q lines follow, each of them contains two different words which has appeared in the dictionary. That are the pairs of words Mahmoud wants to know the relation between basing on the relations he had discovered.

All words in input contain only lowercase English letters and their lengths don't exceed 20 characters. In all relations and in all questions the two words are different.

Output

First, print m lines, one per each relation. If some relation is wrong (makes two words opposite and have the same meaning at the same time) you should print "NO" (without quotes) and ignore it, otherwise print "YES" (without quotes).

After that print q lines, one per each question. If the two words have the same meaning, output 1. If they are opposites, output 2. If there is no relation between them, output 3.

See the samples for better understanding.

Examples
input
3 3 4
hate love like
1 love like
2 love hate
1 hate like
love like
love hate
like hate
hate like
output
YES
YES
NO
1
2
2
2
input
8 6 5
hi welcome hello ihateyou goaway dog cat rat
1 hi welcome
1 ihateyou goaway
2 hello ihateyou
2 hi goaway
2 hi hello
1 hi hello
dog cat
dog hi
hi hello
ihateyou goaway
welcome ihateyou
output
YES
YES
YES
YES
NO
YES
3
3
1
1
2

题意: 就是给定一个文本, 然后每次输入两个词以及两个词之间的关系(1表示为近义词,2表示为相反词),在输入

的过程中如果出现关系矛盾,那么这次的输入无效并且输出NO 否则就输出YES然后就是询问两个词之间的关系, 同样

两个词近义词输出1, 相反词输出2,没有任何关系输出3


讲带全并查集不错的地方:点击打开链接



#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
using namespace std;
const int maxn = 1e5+5;
map<string, int> HASH;
int rel[maxn], pre[maxn];
int n, m, q;

int Find(int x)
{
    if(pre[x] == x) return x;
    int order = pre[x];
    pre[x] = Find(pre[x]);
    rel[x] = (rel[x]+rel[order])%2;
    return pre[x];
}

int main(void)
{
    while(cin >> n >> m >> q)
    {
        HASH.clear();
        int cmd;
        string x, y;
        for(int i = 1; i <= n; i++)
        {
            cin >> x;
            HASH[x] = pre[i] = i;
            rel[i] = 0;
        }
        for(int i = 1; i <= m; i++)
        {
            cin >> cmd >> x >> y;
            cmd--;
            int X = HASH[x], Y = HASH[y];
            int a = Find(X), b = Find(Y);
            if(a != b)
            {
                puts("YES");
                pre[b] = a;
                rel[b] = (rel[X]-rel[Y]+cmd+2)%2;
            }
            else
            {
                int p = (rel[X]-rel[Y]+2)%2;
                puts(cmd==p ? "YES" : "NO");
            }
        }
        while(q--)
        {
            cin >> x >> y;
            int X = HASH[x], Y = HASH[y];
            int a = Find(X), b = Find(Y);
            if(a != b) puts("3");
            else
            {
                int p = (rel[X]-rel[Y]+2)%2;
                printf("%d\n", p+1);
            }
        }
    }
    return 0;
}


GEE:变异系数法在遥感影像分析中的应用及权重计算 本文介绍了在Google Earth Engine(GEE)平台上基于变异系数法的多指标加权遥感影像分析方法。该方法通过计算每个指标的平均值和标准差,进而计算变异系数来评估指标的变化程度。利用变异系数,我们可以计算每个指标的权重,并将其应用于加权和指数的计算,从而提高遥感影像分析的准确性和可靠性。方法应用于计算Risk-Screening Environmental Indicators (RSEI),并以此为例。 阅读详情

相关推荐

STM32H743 LAN8720网口配置避坑指南:用CubeMX v6.5.0快速搞定LWIP+FreeRTOS

本文详细介绍了使用CubeMX v6.5.0配置STM32H743与LAN8720网口的LWIP+FreeRTOS方案,涵盖硬件连接、时钟配置、ETH外设初始化及LWIP协议栈调优等关键步骤。特别针对常见陷阱提供解决方案,帮助开发者快速实现稳定网络通信,适用于嵌入式网络开发场景。

weixin_33739523的博客 364

D. Mahmoud and a Dictionary----带权并查集

D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wants to write a new di

bless295的博客 618

yolov5深度剖析+源码debug级讲解系列(一) yolov5的架构和源码debug准备

前言 前段时间分析了yolov3的源码,这次想带着小伙伴一起把yolov5完全掌握。博主还是保持着一贯的风格,依旧采用debug级别的源码剖析。目的就是让大家可以通过一个系列的文章就把yolov5的架构、设计理念和每一行源码都弄懂。只要小伙伴可以花时间把这个系列读完,就会对yolov5的理解有所提升。 去年参加了kaggle的小麦检测比赛,yolov5在比赛的中段开始呈现霸榜趋势,超越了efficientdet。虽然最后yolov5因为权限等某些问题被kaggle官方禁用了,但是仍然体现出了其强大的能力。值

人唯优的博客 4万+

Codeforces1253D 带权并查集

https://codeforces.com/contest/1253/problem/D n个点 m条边 <=2e5 l<m<r l能到r 则l一定得满足可以到中间点 加最小边数能满足条件 14 8 1 2 2 7 3 4 6 3 5 7 3 8 6 8 11 12 1 #include<bits/stdc++.h> using namespace std; ty...

qq_40423146的博客 278

从零到一:手把手教你用YonBuilder for NCC搭建NC Cloud 2021.11开发环境(含避坑指南)

本文详细指导如何使用YonBuilder for NCC搭建NC Cloud 2021.11开发环境,涵盖硬件要求、软件安装、YonBuilder配置及常见故障排除。特别提供避坑指南,帮助开发者快速上手NCC开发,确保环境配置的原子化分解和开发思维的体系化建立。

weixin_42523326的博客 353

[STM32]HAL STM32F103 软件I2C读写MPU6050(附DMP库移植)

本文介绍了如何在STM32F103C8T6上通过I2C协议与MPU6050传感器通信并实现DMP功能。首先,使用STM32CubeMX配置项目,设置时钟和I2C接口。然后,编写软件I2C协议的读写函数与MPU6050交互。接着,移植DMP库并进行必要修改,获取加速度计和陀螺仪数据,并将其转换为欧拉角显示在OLED上。最后,利用Keil的逻辑分析仪监测I2C时序。

m0_56841583的博客 2335

Codeforces Round #786 (Div. 3) B. Dictionary

time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard output The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combi

Lyriv的博客 515

tinyddp使用详解

tinyddp使用详解: 1、创建服务端,客户端 2、远程调用 3、发布订阅 4、设置日志

LDC,公众号【轻松学编程】 225

CodeForces - 982D Shark 思路+带权并查集

题意: 给定n长度序列,包含n个不同的数,求一个k使得以小于k的数(或区间)分割的所有区间,区间长度相同的同时,区间的个数尽量多,k尽量小 思路: n个数值各不相同,我们能够知道,答案肯定是n个数中某个数+1; 这样我们从小到大遍历n个数,同时维护他们在原序列的下标,这样就将原问题转化为: 将当前的数(a[i])加入之前的所有数的集合,看下标连续的所有区间的长度是否一样,在更新答案(区间...

床前明月光 358

【数字IC刷题】华为海思数字IC笔试题(1)详细解析版

【数字IC刷题】华为海思数字IC笔试题(1)详细解析版

MoorePlus的博客 4229

ArcGIS实验教程——实验三十九:ArcGIS多元分类(ISO聚类分析、最大似然分类、主成分分析)案例教程

文章目录一、ISO聚类1. ISO聚类简介2. ISO聚类进行非监督分类实验操作二、最大似然分类1. 最大似然简介2. 最大似然分类实验案例三、主成分分析1. 主成分分析简介2. 主成分分析实验案例四、配套实验数据下载 一、ISO聚类 1. ISO聚类简介 ISO (interactive self-organization)聚类,即迭代式自组织聚类方法,是最常用的非监督分类算法。首先设定初始聚类中心和聚类数,然后定义相似度准则函数,对全部样本进行调整,调整完毕后重新计算样本均值作为新的聚类中心。在每次.

智慧空间实验室 7831

并查集总结(不看后悔系列)

在计算机科学中,并查集是一种树型的数据结构,用于处理一些不交集(Disjoint Sets)的合并及查询问题。有一个联合-查找算法(union-find algorithm)定义了两个用于此数据结构的操作: ...

一身清贫怎敢入繁华 885

API Streaming Failed 400 <400>InternalError.Algo.InvalidParameter input content must be a string解决方案

本文主要介绍了API Streaming Failed 400 <400> InternalError.Algo.InvalidParameter input content must be a string解决方案,希望能对使用vscode中cline的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 3万+

Codeforces Round #396 (Div. 2)D. Mahmoud and a Dictionary(带权并查集)

题目链接:点击打开链接 思路: 带权并查集水题。  带权并查集可以知道在一个集合里的两点间距离。那么这种同义反义关心恰好对应距离的奇偶。 附上一图: 这就是合并的过程。 细节参见代码: #include #include #include #include #include #include #include #include #include #includ

AC_Arthur的专栏 567

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Codeforces Round #396 (Div. 2)D. Mahmoud and a Dictionary【带权并查集】

D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wants to write a new dictionary t

mengxiang000000 592

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces Round #396 (Div. 2)D. Mahmoud and a Dictionary(带权并查集)

D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wants to write a new di

spark__s的博客 329

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary 并查集

D. Mahmoud and a Dictionary 链接: http://codeforces.com/contest/766/problem/D 代码: 1 #include&lt;cstdio&gt; 2 #include&lt;cstring&gt; 3 #include&lt;cstdlib&gt; 4 #include&lt;cmath&gt; ...

花海 123

Codeforces Round #396 (Div. 2)Mahmoud and a Dictionary

#include #include #include #include #include #include #include #include #include #include using namespace std; const int MAX = 1e5+10; const double eps = 1e-10; const double PI = acos(-1.0); string st

Stone的博客 217

Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary

扩展域并查集

我们仍未知道那天所看见的花的名字。 224

Codeforces Round #396 (Div. 2)-D. Mahmoud and a Dictionary(关系并查集)

题目链接 题目大意: n个单词,m个关系,q次查询 有两种关系: 1 a b表示a,b两个单词同义 2 a b表示a,b两个单词反义 如果关系跟之前的关系冲突则无视当前关系 每次查询问两个单词属于1还是2,都不属于则输出3一看就发现跟poj1703和poj1182两道关系并查集很像,,可以说是结合后的题。 这里我把关系1,2变成0,1刚好是%2后的数PS:为什

No Program No Life 417

Codeforces Round #396 (Div. 2)-D. Mahmoud and a Dictionary(并查集)

原题链接 D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wan

L. 499

Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary (并查集)

D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wants to write a new di

LzyRapX 546

Codeforces Round #396 (Div. 2) D.Mahmoud and a Dictionary

D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wants to write a new dictionary...

weixin_30920091的博客 95

Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary(并查集)

D. Mahmoud and a Dictionarytime limit per test:4 secondsmemory limit per test:256 megabytesinput:standard inputoutput:standard outputMahmoud wants to write a new dictionary that contains n words and re

妍恐龙的博客....^~^眼熟我 376
上一篇: Codeforces Round #396 (Div. 2) C. Mahmoud and a Message(DP)
下一篇: POJ 3041 Asteroids(最小顶点覆盖)
cillyb
博客等级 码龄11年 225粉丝 497原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值