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

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

codeforces766D Mahmoud and a Dictionary [并查集]【數據結構】

2019-11-10 16:53:18
字體:
來源:轉載
供稿:網友

題目連接:http://codeforces.com/contest/766/PRoblem/D

—————————————————————————————-. D. Mahmoud and a Dictionary time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard 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個查詢, 關系是兩個單詞是同義詞還是反義詞,對于當前的這條關系如果與前述關系不符則忽略, 查詢是兩個單詞之間的關系是同義詞還是反義詞還是未知.

解題思路: 很好想到并查集來維護同義詞,然后用另一個數組怎樣的表示兩堆之間的反義詞關系,

最開始是想對每堆進行染色,兩個堆中一個染成+n,另一個染成-n,加和為零表示敵對關系,然后可以在維護一個并查集或者怎樣 ,但是最后GG了

看了題解 發現用另一個數組來維護本堆的反義詞的堆是哪一個,真是奧妙重重。666

這樣的話 這個題目就簡單清晰多了,直接維護就行了。

注意對于m條關系的判定時的細節就好了,詳見代碼。

借(chao)鑒(xi)這里<–戳戳戳

附本題代碼 —————————————————————————————-.

int n,m,q,op;string str,str1,str2;map<string,int>mmp;int pre[N],opp[N];int findi(int x){ int r = x; while(r != pre[r]) r=pre[r]; int i=x,j; while(i!=j){ j=pre[i]; pre[i]=r; i=j; } return r;}void init(){ mmp.clear(); Rep(i,0,n) pre[i]=i,opp[i]=0;}int main(){ while(cin>>n>>m>>q){ init(); Rep(i,1,n) cin>>str,mmp[str]=i; Rep(i,1,m){ cin>>op>>str1>>str2; int x = mmp[str1],y = mmp[str2]; int u = findi(x),v = findi(y); int uu= findi(opp[u]),vv= findi(opp[v]); if(op==1){ if(uu!=v){ puts("YES"); pre[u]=v; if(uu&&vv) pre[uu]=vv; if(!vv) opp[v]=uu; } else puts("NO"); } else { if(u!=v) { puts("YES"); if(uu) pre[v]=uu; else opp[u]=v; if(vv) pre[u]=vv; else opp[v]=u; } else puts("NO"); } } Rep(i,1,q){ cin>>str1>>str2; int x = mmp[str1],y = mmp[str2]; int u = findi(x),v = findi(y); int uu= findi(opp[u]),vv= findi(opp[v]); if (u==v) puts("1"); else { if (uu==v||vv==u) puts("2"); else puts("3"); } } } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
亚洲品质视频自拍网| 激情懂色av一区av二区av| 欧洲日韩成人av| 亚洲视频在线播放| 欧美日本国产在线| 欧美裸身视频免费观看| 亚洲精品福利在线观看| 国产精品网站视频| 96pao国产成视频永久免费| 国产精品成人aaaaa网站| 国产成人+综合亚洲+天堂| 国产亚洲一区二区精品| 国产欧美一区二区三区在线看| 92看片淫黄大片欧美看国产片| 日韩欧美一区二区在线| 午夜精品一区二区三区视频免费看| 国产欧美最新羞羞视频在线观看| 欧美一区深夜视频| 日韩日本欧美亚洲| 91欧美激情另类亚洲| 日韩精品极品在线观看| 精品伊人久久97| 韩国视频理论视频久久| 久久久久久久电影一区| 亚洲视频在线免费看| 琪琪亚洲精品午夜在线| 亚洲字幕一区二区| 91免费综合在线| 国产精品一区二区在线| 亚洲sss综合天堂久久| 亚洲丝袜av一区| 午夜精品国产精品大乳美女| 久久精品亚洲一区| 国产成人精品在线| 成人国内精品久久久久一区| 亚洲欧美国产精品va在线观看| 日本亚洲欧洲色| 97香蕉超级碰碰久久免费软件| 91av视频在线播放| 国产欧美一区二区| 欧美在线视频网| 国产一区二区三区在线播放免费观看| 欧美精品一二区| 色综合伊人色综合网| 国产美女久久精品| 久久午夜a级毛片| 久久免费成人精品视频| 国产精品久久久久久中文字| 欧洲亚洲女同hd| 欧美视频免费在线观看| 亚洲精品中文字幕女同| 欧美亚洲视频在线观看| 欧美成人精品在线观看| 欧美香蕉大胸在线视频观看| 成人情趣片在线观看免费| 成人精品一区二区三区电影黑人| 91中文在线观看| 欧美激情在线观看| 97精品国产97久久久久久| 色偷偷9999www| 91黑丝高跟在线| 国产成人黄色av| 日本欧美一二三区| 亚洲天堂视频在线观看| 伊人伊成久久人综合网小说| 日韩av在线网| 国产精品亚洲аv天堂网| 国产精品久久久久久久9999| 国产精品av在线播放| 欧美一区二区三区图| 国自在线精品视频| 在线电影av不卡网址| 人人做人人澡人人爽欧美| 国产成人久久久精品一区| 日韩成人xxxx| 亚洲美女又黄又爽在线观看| 91欧美视频网站| 久久久久久久久久久久久久久久久久av| 96sao精品视频在线观看| 一区二区三区视频在线| 亚洲欧美日韩直播| 揄拍成人国产精品视频| 国产欧美日韩中文字幕在线| 成人免费观看a| 成人免费观看49www在线观看| 国产精品吹潮在线观看| 日韩在线视频网站| 91精品国产自产在线| 动漫精品一区二区| 欧美中文在线观看国产| 亚洲高清免费观看高清完整版| 日韩av在线免费播放| 国产精品综合久久久| 黑人巨大精品欧美一区二区三区| 欧美日韩免费网站| 久久99久久99精品中文字幕| 亚洲人成绝费网站色www| 国产精品综合不卡av| 国产精品中文字幕在线观看| 操91在线视频| 午夜伦理精品一区| 91午夜理伦私人影院| 俺去亚洲欧洲欧美日韩| 欧美激情精品久久久久久变态| 欧美极品少妇xxxxⅹ免费视频| 国产一区二区在线免费视频| 亚洲欧美制服第一页| 国产一区二区三区四区福利| 久久久国产91| www.欧美三级电影.com| 成人国产在线视频| 欧美一级bbbbb性bbbb喷潮片| 国产a级全部精品| 日韩精品久久久久久福利| 成人淫片在线看| 97视频国产在线| 91精品视频网站| 欧美日韩国产一区在线| 欧亚精品在线观看| 久久免费视频这里只有精品| 亚洲精品资源在线| 欧美一级大片视频| 欧美性猛交xxxx免费看久久久| 欧日韩不卡在线视频| 91精品国产91久久久久久| 精品成人在线视频| 国产精品欧美激情在线播放| 91国内揄拍国内精品对白| 大伊人狠狠躁夜夜躁av一区| www.日韩视频| 在线一区二区日韩| 精品无人国产偷自产在线| 国产精品一区二区三区成人| 国产精品视频自在线| 欧美激情二区三区| 欧美日韩国产精品一区二区三区四区| 欧美最顶级的aⅴ艳星| 91在线播放国产| 97在线视频一区| 亚洲精品一区在线观看香蕉| 成人自拍性视频| 色婷婷成人综合| 视频一区视频二区国产精品| 亚洲性xxxx| 久久久极品av| 亚洲成年网站在线观看| 国产不卡一区二区在线播放| 日韩美女写真福利在线观看| 热久久美女精品天天吊色| 中文字幕亚洲综合久久筱田步美| 日韩免费中文字幕| 精品小视频在线| 精品少妇一区二区30p| 亚洲欧美第一页| 国产一区二区三区直播精品电影| 国产精品直播网红| 久久久国产一区二区三区| 亚洲老司机av| 亚洲va电影大全| 国产精品免费福利| 国产成人亚洲综合青青| 国产成人精品免费视频| 一区二区三区日韩在线| www.久久久久久.com|