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 ;
}

最新文章

  1. 【13-Annotation】
  2. js实现一个可以兼容PC端和移动端的div拖动效果
  3. mysql-databaseython 3.4.0 with MySQL database
  4. MyEclipse开发JAX-RS架构WebServices收发JSON数据格式
  5. 内容在某div中滚动
  6. Survival(ZOJ 2297状压dp)
  7. gridview实现表格编辑功能
  8. JAVA编程心得-JAVA实现CRC-CCITT(XMODEM)算法
  9. Java 特殊字符的String.split的分割(. \ * | \\)
  10. Remove Untagged Images From Docker
  11. mysql的使用相关问题
  12. EXCEL记录
  13. 找到排序矩阵中从小到大第K个数字
  14. 纯小白入手 vue3.0 CLI - 3.2 - 路由的初级使用
  15. 在IDEA中修改项目的名称
  16. 通过.json()将服务器返回的字符串转换成字典
  17. BZOJ.1003.[ZJOI2006]物流运输(DP 最短路Dijkstra)
  18. dede中arcurl的解析
  19. springcloud微服务实战:Eureka+Zuul+Feign/Ribbon+Hystrix Turbine+SpringConfig+sleuth+zipkin
  20. tsar的使用

热门文章

  1. 【Advanced Windows Phone Programming】在windows phone 8中解码mp3 和编码pcm
  2. 1、VGG16 2、VGG19 3、ResNet50 4、Inception V3 5、Xception介绍——迁移学习
  3. BZOJ_2801_[Poi2012]Minimalist Security_dfs树+特判+乱搞
  4. C++模板之typename和class关键字的区别
  5. bzoj 3027 [Ceoi2004] Sweet —— 生成函数
  6. 2.7 HBase架构深入剖析
  7. TypeScript完全解读(26课时)_19.其他重要更新
  8. UVaLive 3635 Pie (二分)
  9. javascript runat server
  10. ORM取数据很简单!是吗?