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 nm and q (2 ≤ n ≤ 105, 1 ≤ m, q ≤ 105) where n is the number of words in the dictionary, m is 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

题意:a和b是近义词,a和c是反义词,那么b和c也是反义词,有时候主角会搞错,造成两个词互相矛盾的情况,问输入的这样数据关系怎么样,有没有错误关系(看样例)

比如 love和like是1关系,love和hate是2关系,然后1 hate like互相矛盾输出NO,接下来问这些正确的关系如何

解法:

1 看到两个关联就用并查集,当然字符串我们标记一下

2 关系是1的我们合并x,y和x+n,y+n,关系是2的我们合并x,y+n和y,x+n

3 一边合并一边判断是不是YES和NO

4 然后查询两个词的关系。。就是把代码复制了一下

 #include<bits/stdc++.h>
using namespace std;
const int maxn=1e5;
int tree[*maxn];
int Find(int x)
{
if(x==tree[x])
return x;
return tree[x]=Find(tree[x]);
} void Merge(int x,int y)
{
int fx=Find(x);
int fy=Find(y);
if(fx!=fy)
tree[fx]=fy;
}
int n,m,d;
string s;
int Num;
map<string,int>Mp;
int main(){
cin>>n>>m>>d;
for(int i=;i<=n;i++){
cin>>s;
if(Mp[s]==){
Mp[s]=Num;
Num++;
}
}
for(int i=;i<=*n;i++){
tree[i]=i;
}
for(int i=;i<=m;i++){
string s1,s2;
int num;
cin>>num>>s1>>s2;
int ans1=Mp[s1];
int ans2=Mp[s2];
int pos1=Find(ans1);
int pos2=Find(ans1+n);
int Pos1=Find(ans2);
int Pos2=Find(ans2+n);
if((pos1==Pos2||pos2==Pos1)&&num==){
cout<<"NO"<<endl;
}else if((pos1==Pos1||pos2==Pos2)&&num==){
cout<<"NO"<<endl;
}else{
cout<<"YES"<<endl;
if(num==){
Merge(pos1,Pos1);
Merge(pos2,Pos2);
}else{
Merge(pos1,Pos2);
Merge(pos2,Pos1);
}
}
}
for(int i=;i<=d;i++){
string s1,s2;
cin>>s1>>s2;
int ans1=Mp[s1];
int ans2=Mp[s2];
int pos1=Find(ans1);
int pos2=Find(ans1+n);
int Pos1=Find(ans2);
int Pos2=Find(ans2+n);
if(pos1==Pos1){
cout<<""<<endl;
}else if(pos1==Pos2){
cout<<""<<endl;
}else{
cout<<""<<endl;
}
}
return ;
}

Codeforces Round #396 (Div. 2) D的更多相关文章

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

    D. Mahmoud and a Dictionary 题目连接: http://codeforces.com/contest/766/problem/D Description Mahmoud wa ...

  2. Codeforces Round #396 (Div. 2) A,B,C,D,E

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  3. Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

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

    地址:http://codeforces.com/contest/766/problem/D 题目: D. Mahmoud and a Dictionary time limit per test 4 ...

  5. Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip dfs 按位考虑

    E. Mahmoud and a xor trip 题目连接: http://codeforces.com/contest/766/problem/E Description Mahmoud and ...

  6. Codeforces Round #396 (Div. 2) C. Mahmoud and a Message dp

    C. Mahmoud and a Message 题目连接: http://codeforces.com/contest/766/problem/C Description Mahmoud wrote ...

  7. Codeforces Round #396 (Div. 2) B. Mahmoud and a Triangle 贪心

    B. Mahmoud and a Triangle 题目连接: http://codeforces.com/contest/766/problem/B Description Mahmoud has ...

  8. Codeforces Round #396 (Div. 2) A. Mahmoud and Longest Uncommon Subsequence 水题

    A. Mahmoud and Longest Uncommon Subsequence 题目连接: http://codeforces.com/contest/766/problem/A Descri ...

  9. Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip

    地址:http://codeforces.com/contest/766/problem/E 题目: E. Mahmoud and a xor trip time limit per test 2 s ...

随机推荐

  1. POJ 2485 Highways(最小生成树+ 输出该最小生成树里的最长的边权)

                                                                                                         ...

  2. #pragma once与#ifndef

    都是为了避免同一个头文件被包含多次.在编译器对这两种方式都支持的情况下,区别很小. 方式一: #pragma once ...//这里放声明语句 方式二: #ifndef 宏名 #def 宏名 ... ...

  3. legend2---开发日志12(vue如何进一步学习)

    legend2---开发日志12(vue如何进一步学习) 一.总结 一句话总结:还是得找教程(比如视频),自己摸索太浪费时间,也容易踩坑和抓不住重点 还是得找教程(比如视频),自己摸索太浪费时间,也容 ...

  4. C#开发遇到的常见问题及知识点

    今天遇到的类型初始值设定项引发异常的原因是:类没有添加[Serializable]属性. this.DialogResult = System.Windows.Forms.DialogResult.O ...

  5. linux系统配置之服务程序的开机自启动(centos)

    CentOS安装好apache.mysql等服务器程序后,并没有设置成开机自动启动的,为避免重启后还要手动开启web等服务器,还是做下设置好,其实设置很简单,用chkconfig命令就行了. 例如,要 ...

  6. golang 关于golang.org/x包问题

    关于golang.org/x包问题 由于谷歌被墙,跟谷歌相关的模块无法通过go get来下载,解决方法: git clone https://github.com/golang/net.git $GO ...

  7. plsql导入cvs 时提示missing right parenthesis

    删除自动生成的时间格式值,如:SQL function框里自动生成的值

  8. 谈谈java中成员变量与成员方法继承的问题

    谈谈java中成员变量与成员方法继承的问题 关于成员变量和成员方法的的继承问题,我也可以做一个小测试,来看看结果. 首先我们先创建一个父类:

  9. 使用 WinSCP(下载) 上文件到 Linux图文教程

        问题导读: 1.如何远程链接? 2.如何上传文件? 3.如何对立面的文件进行操作? 4.什么情况下会链接失败? https://yunpan.cn/cYWtNMycjeVPv 访问密码 4f7 ...

  10. python optparse模块的简单用法

    # coding = utf-8 from optparse import OptionParser from optparse import OptionGroup usage = 'Usage: ...