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

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

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

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

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
色777狠狠综合秋免鲁丝| 国产精品成人v| 国产欧美日韩91| 欧美午夜电影在线| 91亚洲精品在线| 九九热最新视频//这里只有精品| 久久精品国产亚洲| 国产精品99久久久久久久久| 亚洲资源在线看| 91免费高清视频| 国产热re99久久6国产精品| 国产精品扒开腿做爽爽爽视频| 中文字幕欧美专区| 日韩美女福利视频| www.亚洲免费视频| 欧美日在线观看| 日韩福利视频在线观看| 成人免费xxxxx在线观看| 中文字幕一区二区精品| 成人福利网站在线观看| 性色av一区二区三区免费| 91在线观看免费| 这里精品视频免费| 岛国视频午夜一区免费在线观看| 久久免费少妇高潮久久精品99| 一区二区三区亚洲| 亚洲成人激情在线观看| www.美女亚洲精品| 久久久国产一区二区三区| 亚洲性视频网站| 日韩精品视频观看| 亚洲精品国产品国语在线| 日韩精品在线观看一区二区| 亚洲影院色在线观看免费| 91sa在线看| 91久久国产精品91久久性色| 欧美激情伊人电影| 久久久国产精品视频| 久久91亚洲人成电影网站| 欧美激情综合亚洲一二区| 欧美成人黄色小视频| 亚洲最大av在线| 日本精品中文字幕| 伊人青青综合网站| 黄色成人在线播放| 国产在线视频一区| 午夜剧场成人观在线视频免费观看| 久久久日本电影| 成人写真视频福利网| 中文字幕免费精品一区| 国内精品久久久久久影视8| 久久亚洲欧美日韩精品专区| 日韩av网站大全| 在线播放精品一区二区三区| 欧美亚洲国产精品| 国产丝袜精品第一页| 茄子视频成人在线| 日韩小视频在线| 91高潮在线观看| 国内精品美女av在线播放| 深夜福利91大全| 日韩av电影国产| 黄色一区二区在线观看| 欧美人与性动交a欧美精品| 日韩精品在线免费播放| 亚洲精品日韩久久久| 欧美黑人一区二区三区| 91国偷自产一区二区三区的观看方式| 性欧美xxxx视频在线观看| 日本一欧美一欧美一亚洲视频| 亚洲激情在线视频| 成人福利网站在线观看11| 久久久久久久av| 欧美日韩裸体免费视频| 欧美日韩国产一区中文午夜| 高清视频欧美一级| 亚洲精品自拍第一页| 国产精品69精品一区二区三区| 黑人巨大精品欧美一区免费视频| 国产亚洲欧洲高清| 国产美女精品免费电影| 国产精品黄页免费高清在线观看| 久久久精品视频在线观看| 日韩精品视频三区| 国产精国产精品| 久久久久久网站| 日产精品99久久久久久| 国产精品久久久久久久久久99| 精品国模在线视频| 欧美日韩国产va另类| 永久免费看mv网站入口亚洲| 国产精品久久久久9999| 少妇高潮久久久久久潘金莲| 奇米影视亚洲狠狠色| 亚洲免费视频一区二区| 欧美日韩国产精品一区二区三区四区| 91在线视频免费| 欧美日韩国产影院| 日产精品久久久一区二区福利| 国产亚洲精品综合一区91| 国产精品色午夜在线观看| 国产精品久久久久久久久久新婚| 欧美人成在线视频| 亚洲性线免费观看视频成熟| 精品国产一区二区三区久久狼黑人| 精品久久久av| 97精品国产91久久久久久| 日韩电影网在线| 亚洲人成五月天| 庆余年2免费日韩剧观看大牛| 欧美视频二区36p| 欧美性xxxxx极品娇小| 日韩精品高清在线观看| 国产精品日韩欧美大师| 欧美激情精品久久久久久变态| 欧美激情精品久久久久久久变态| 91成人精品网站| 精品久久香蕉国产线看观看亚洲| 久久久久久综合网天天| 亚洲欧美日韩一区二区三区在线| 精品av在线播放| 91国自产精品中文字幕亚洲| 91视频国产精品| 欧美黄色片视频| 亚洲r级在线观看| 亚洲人在线视频| 国产精品久久综合av爱欲tv| 国产亚洲精品激情久久| 欧美在线观看日本一区| 欧美极品少妇全裸体| 最新中文字幕亚洲| 色综久久综合桃花网| 92看片淫黄大片看国产片| 欧洲中文字幕国产精品| 国产成人精品av在线| 日本19禁啪啪免费观看www| 国产成人精品久久二区二区91| 国产精品成人aaaaa网站| 日韩美女福利视频| 亚洲国产美女久久久久| 欧美激情a∨在线视频播放| 在线色欧美三级视频| 欧美性猛交xxxx免费看久久久| 国产有码一区二区| 精品亚洲一区二区| 亚洲天堂免费观看| 狠狠做深爱婷婷久久综合一区| 精品亚洲夜色av98在线观看| 日韩欧美精品免费在线| 亚洲系列中文字幕| 国产精品视频白浆免费视频| 久青草国产97香蕉在线视频| 欧美乱大交做爰xxxⅹ性3| 一区二区三区 在线观看视| 国内精品小视频| 福利一区视频在线观看| 久久福利视频网| 国产一区二区三区视频免费| 97国产真实伦对白精彩视频8| 欧美孕妇性xx| 国产精品久久久久久久久| 98精品国产自产在线观看| 伊人青青综合网站| 国产精品扒开腿爽爽爽视频|