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

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

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

2019-11-09 21:02:19
字體:
來源:轉載
供稿:網友

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
精品免费在线观看| 国产成人精品视频在线| 日韩国产精品一区| 日韩av中文字幕在线免费观看| 91免费电影网站| 成人亚洲综合色就1024| 国产精品美女久久久久久免费| 欧美黄色片免费观看| 国产精品色视频| 久久久久国产精品www| 精品久久香蕉国产线看观看亚洲| 久久久91精品国产一区不卡| 日韩成人av在线播放| 亚洲人成在线一二| 91夜夜未满十八勿入爽爽影院| 高清在线视频日韩欧美| 91精品视频在线看| 青青草成人在线| 欧美壮男野外gaytube| 精品无人国产偷自产在线| 欧美极品在线播放| 亚洲深夜福利视频| 一本色道久久综合亚洲精品小说| 萌白酱国产一区二区| 欧美亚洲日本网站| 欧美精品一二区| 欧美xxxx做受欧美.88| 日韩在线精品视频| 国产精品久久久久久久久| 日韩电影中文 亚洲精品乱码| 久久精品久久久久电影| 精品国产鲁一鲁一区二区张丽| 欧美视频在线视频| 北条麻妃一区二区在线观看| 九九视频直播综合网| 黄色成人在线免费| 91九色国产在线| 成人福利网站在线观看| 国语自产精品视频在线看一大j8| 国产噜噜噜噜久久久久久久久| 日韩在线不卡视频| 51精品在线观看| 欧美乱妇40p| 国产日韩欧美91| 91久久精品国产| 国产精品久久久久久久美男| 午夜免费在线观看精品视频| 国内精品小视频| 欧美午夜女人视频在线| 日韩av大片在线| 国产z一区二区三区| 性色av一区二区三区| 久久男人资源视频| 在线观看亚洲视频| 欧美极品少妇xxxxⅹ裸体艺术| 国产丝袜高跟一区| 亚洲一区二区三区在线视频| 亚洲成人xxx| 久久久国产精彩视频美女艺术照福利| 日本精品免费观看| 国产免费一区视频观看免费| 久久视频在线免费观看| 国产一区二区三区精品久久久| 色偷偷91综合久久噜噜| 国外成人在线播放| 97色在线视频观看| 91中文在线视频| 国产精品久久久久久久7电影| 日韩电影大全免费观看2023年上| 亚洲色图国产精品| 亚洲精品久久久一区二区三区| 成人久久久久爱| 久久久久久久影院| 精品久久久久久| 国产精品美女999| 国产激情久久久| 日韩小视频在线观看| 欧美乱大交xxxxx另类电影| 欧美国产日韩中文字幕在线| 久久久中文字幕| 欧美俄罗斯乱妇| 欧美日产国产成人免费图片| 两个人的视频www国产精品| 久久免费国产视频| 色综合久久悠悠| 国产成人a亚洲精品| 欧美一性一乱一交一视频| 欧美电影院免费观看| 自拍视频国产精品| 欧美电影电视剧在线观看| 亚洲精品国产成人| 亚洲伊人第一页| 国内精品视频在线| 亚洲成人精品av| 伊人久久久久久久久久| 国产成人精品久久亚洲高清不卡| 亚洲午夜精品久久久久久性色| 亚洲娇小xxxx欧美娇小| 久久人人爽亚洲精品天堂| 亚洲欧美999| 高清在线视频日韩欧美| 国产91精品在线播放| 亚洲a∨日韩av高清在线观看| 欧美日韩另类字幕中文| 高清亚洲成在人网站天堂| 国产日韩综合一区二区性色av| 久久久中精品2020中文| 国产精品99久久久久久人| 欧美黄色片视频| 成人高清视频观看www| 日韩欧美成人免费视频| 丝袜亚洲欧美日韩综合| 色偷偷9999www| 精品国产一区二区三区久久狼5月| 欧美黄色片视频| 亚洲91av视频| 亚洲成人激情在线观看| 国产精品久久久久久av下载红粉| 日韩一二三在线视频播| 日韩在线视频免费观看高清中文| 一区二区三区在线播放欧美| 51ⅴ精品国产91久久久久久| 亚洲福利视频在线| 亚洲一区第一页| 69av视频在线播放| 欧美一区亚洲一区| 亚洲精品97久久| 亚洲国模精品私拍| 国产精品a久久久久久| 在线日韩精品视频| 97在线精品国自产拍中文| 97久久国产精品| 57pao成人永久免费视频| 亚洲人线精品午夜| 国产精品夜间视频香蕉| 国产精品私拍pans大尺度在线| 日韩精品视频在线观看免费| 国产精品丝袜白浆摸在线| 欧美日韩亚洲一区二| 国产精品爽黄69| 亚洲欧美日韩图片| 国产精品69久久久久| 国产成人精品久久亚洲高清不卡| 国产精品久久久av久久久| 欧美与黑人午夜性猛交久久久| 91精品国产成人www| 中文字幕一区二区三区电影| 自拍偷拍亚洲一区| 68精品久久久久久欧美| 5278欧美一区二区三区| 日韩一区二区久久久| 久久亚洲一区二区三区四区五区高| 日韩中文字幕在线精品| 日韩欧美精品在线观看| 在线视频欧美性高潮| xxxx性欧美| 国产成人激情小视频| 亚洲精品国产电影| 国产大片精品免费永久看nba| 国产亚洲精品一区二区| 欧美野外wwwxxx| 欧美精品久久久久久久免费观看| 91色琪琪电影亚洲精品久久| 国产欧美在线看|