亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

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

2019-11-10 17:17:48
字體:
來源:轉載
供稿:網友

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, 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 題意:n個單詞,m個關系,q個詢問。關系中,1表示兩個詞是同義詞,2表示是反義詞,如果是與之前矛盾的關系,輸出no,跳過本次,否則輸出yes。q次提問,兩個次數是同義的輸出1,反義輸出2,不知道輸出3. 題解:很經典的并查集。用2*i表示這個詞,2*i-1表示反義。并查集處理一下即可。 代碼:

#include <bits/stdc++.h>#define ll long longusing namespace std;const int N=1e5+10;int n,m,q,x;string str,a,b;map<string,int>mp;int pre[N<<1];int find(int x){ return x==pre[x]?x:pre[x]=find(pre[x]);}void mx(int x,int y){ x=find(x); y=find(y); if(x!=y) pre[x]=y;}int main(){ cin>>n>>m>>q; for(int i=1;i<=2*n;i++) pre[i]=i; for(int i=1;i<=n;i++) { cin>>str; mp[str]=i; } while(m--) { cin>>x>>a>>b; if(x==1) { if(find(mp[a]*2)==find(mp[b]*2-1)) { cout<<"NO"<<endl; continue; } else { cout<<"YES"<<endl; mx(mp[a]*2,mp[b]*2); mx(mp[a]*2-1,mp[b]*2-1); } } else { if(find(mp[a]*2)==find(mp[b]*2)) { cout<<"NO"<<endl; continue; } else { cout<<"YES"<<endl; mx(mp[a]*2,mp[b]*2-1); mx(mp[a]*2-1,mp[b]*2); } } } while(q--) { cin>>a>>b; if(find(mp[a]*2)==find(mp[b]*2)||find(mp[a]*2-1)==find(mp[b]*2-1)) cout<<"1"<<endl; else if(find(mp[a]*2)==find(mp[b]*2-1)||find(mp[a]*2-1)==find(mp[b]*2)) cout<<"2"<<endl; else cout<<"3"<<endl; } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
日本a级片电影一区二区| 中文字幕一区日韩电影| 日韩一区二区在线视频| 欧美激情一区二区三级高清视频| 国产suv精品一区二区| 日韩欧美在线视频免费观看| 精品国产精品三级精品av网址| 91精品综合久久久久久五月天| 成人av番号网| 97超视频免费观看| 欧美日韩一区二区三区在线免费观看| 久久久久免费视频| 在线亚洲男人天堂| 一区二区三区国产在线观看| 亚洲精品免费av| 美日韩丰满少妇在线观看| 91免费福利视频| 国产一区二区三区网站| 亚洲全黄一级网站| 韩国19禁主播vip福利视频| 中文精品99久久国产香蕉| 一级做a爰片久久毛片美女图片| 国产精品精品视频一区二区三区| 九九热99久久久国产盗摄| 国产97色在线| 日韩欧美主播在线| 91九色单男在线观看| 欧美日韩综合视频| 日本久久久久亚洲中字幕| 欧美一区视频在线| 国产欧美日韩中文字幕在线| 久久久亚洲欧洲日产国码aⅴ| 亚洲香蕉成视频在线观看| 日韩在线观看免费| 国产精品成人v| 久久精品人人爽| 91tv亚洲精品香蕉国产一区7ujn| 欧美做受高潮电影o| 亚洲视频在线播放| 成人国内精品久久久久一区| 2025国产精品视频| 91国产一区在线| 成人乱色短篇合集| 中文字幕欧美专区| 成人免费激情视频| 日本久久久a级免费| 欧美性猛交xxxx乱大交蜜桃| 国产成人精品国内自产拍免费看| 亚洲人成电影网站| 亚洲免费视频网站| 亚洲国产婷婷香蕉久久久久久| 久久99热精品这里久久精品| 国产成人精品优优av| 久久免费国产精品1| 欧美成人黑人xx视频免费观看| 欧美黑人xxx| 国产欧美一区二区三区四区| 亚洲国产欧美自拍| 国产精品亚洲网站| 国产伦精品一区二区三区精品视频| 亚洲欧洲视频在线| 国产欧美一区二区白浆黑人| 亚洲美女av电影| 精品久久中文字幕| 日韩有码片在线观看| 亚洲天堂一区二区三区| 日韩国产欧美精品在线| 欧美一级片久久久久久久| 国产精品爱啪在线线免费观看| 2019中文字幕在线免费观看| 亚洲人精选亚洲人成在线| 欧美亚洲国产成人精品| 最新国产精品亚洲| 欧美性视频精品| www.久久草.com| 精品在线观看国产| 久久免费在线观看| 欧美俄罗斯乱妇| 亚洲第一视频在线观看| 国产精品偷伦一区二区| 原创国产精品91| 亚洲综合日韩中文字幕v在线| 久久亚洲精品网站| 国产精品黄视频| 日韩中文字幕久久| 日本成人免费在线| 国产精品香蕉av| 久久久久久久久电影| 欧美日韩亚洲视频一区| 日韩国产高清视频在线| 亚洲va码欧洲m码| 亚洲成在人线av| 2019最新中文字幕| 亚洲欧洲第一视频| 国产欧洲精品视频| 亚洲一区二区三区在线免费观看| 亚洲精美色品网站| 国产精品91在线观看| 国产精品视频xxx| 日韩有码在线观看| 亚洲免费av片| 国产精品99久久久久久久久久久久| 精品中文字幕在线2019| 欧美日韩免费观看中文| 色999日韩欧美国产| 国产精品欧美激情在线播放| 亚洲a成v人在线观看| 国产精品久久久久久久久男| 亚洲人午夜精品| 久久福利视频导航| 欧美精品福利在线| 成人在线视频福利| 亚洲国产日韩欧美在线99| 欧美电影免费观看大全| 久久频这里精品99香蕉| 国内精久久久久久久久久人| 国产成人97精品免费看片| 热久久免费国产视频| 欧美激情图片区| 亚洲欧洲第一视频| 日韩精品在线观看网站| 欧美黑人xxxⅹ高潮交| 国内伊人久久久久久网站视频| 欧美精品做受xxx性少妇| 狠狠躁夜夜躁人人爽天天天天97| 欧美电影在线观看高清| 亚洲精品日韩av| 国产精品嫩草视频| 97久久久免费福利网址| 国模私拍视频一区| 久久久久久久久久久人体| 日韩天堂在线视频| 欧美在线性爱视频| 亚洲天堂2020| 国产黑人绿帽在线第一区| 欧美黑人一区二区三区| 国产91对白在线播放| 欧美野外猛男的大粗鳮| 热99久久精品| 久久免费少妇高潮久久精品99| 亚洲丁香婷深爱综合| 日韩在线欧美在线| 国产一区二区三区三区在线观看| 久久久国产精品一区| 欧美大片在线免费观看| 成人精品一区二区三区| 92福利视频午夜1000合集在线观看| 亚洲在线第一页| 亚洲欧美在线免费| 欧美视频在线免费看| 91免费高清视频| 国产精品丝袜一区二区三区| 色播久久人人爽人人爽人人片视av| 亚洲成人性视频| 久久久久久久av| 亚洲一区免费网站| 国内精品一区二区三区四区| 亚洲精品美女免费| 久久久精品久久久| 精品久久久久久久久久久久久久| 免费91麻豆精品国产自产在线观看| www.xxxx精品| 久久精品视频在线| 国产精品自产拍在线观看|