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

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

Mahmoud and a Dictionary codeforces396 div2 D

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

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個詢問,問你兩個單詞之間的關系是什么; 同義詞輸出1,反義詞輸出2,不確定輸出3;

帶權并查集:不懂的可以看下這道:http://blog.csdn.net/littlewhite520/article/details/53521037 只有兩個值 1和 2 兩種狀態所以%2就行,保持在 0 1,要輸出不確定的為3,記住,不在一棵樹里面的就是不確定的。

#include <bits/stdc++.h>using namespace std;const int maxn=1e5+7;int f[maxn];int relation[maxn];map <string,int > mp;int find(int x){ if(x!=f[x]) { int t=f[x]; f[x]=find(f[x]); relation[x]=(relation[x]+relation[t])%2; } return f[x];}int main(){ int n,m,q; while(cin>>n>>m>>q) { string s; for(int i=0;i<n;i++) { cin>>s; mp[s]=i; } for(int i=0;i<n;i++) { f[i]=i; relation[i]=0; } string s1; int v; while(m--) { cin>>v>>s>>s1; v--; int f1=mp[s]; int f2=mp[s1]; int t1=find(f1); int t2=find(f2); if(t1!=t2) { printf("YES/n"); f[t1]=t2; relation[t1]=(v-relation[f1]+relation[f2]); } else { int p=(relation[f1]-relation[f2]+2)%2; if(p==v) puts("YES"); else puts("NO"); } } while(q--) { cin>>s>>s1; int f1=mp[s]; int f2=mp[s1]; int t1=find(f1); int t2=find(f2); if(t1!=t2) { puts("3"); } else { int p=(relation[f1]-relation[f2]+2)%2; printf("%d/n",p+1 ); } } }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
精品人伦一区二区三区蜜桃免费| 久久久亚洲影院你懂的| 中文字幕日韩av综合精品| 日韩小视频在线| 国产亚洲欧洲在线| 欧美极品美女电影一区| 欧美黑人视频一区| 日韩电影免费观看在线| 欧美肥老太性生活视频| 在线观看国产欧美| 这里精品视频免费| 欧美性视频在线| 成人妇女免费播放久久久| 国产精品尤物福利片在线观看| 98精品国产高清在线xxxx天堂| 欧美日韩成人在线播放| 精品中文字幕在线2019| 久久久久久尹人网香蕉| 6080yy精品一区二区三区| 久久久久这里只有精品| 亚洲成人在线网| 欧美一级高清免费播放| 欧美成人精品在线播放| 国产美女精品免费电影| 成人精品在线观看| 国产精品电影一区| 精品久久中文字幕| 97久久伊人激情网| 亚洲成年人影院在线| 久久久电影免费观看完整版| 亚洲乱码国产乱码精品精天堂| 亚洲精品资源美女情侣酒店| 亚洲国产黄色片| 欧美在线视频网站| 欧美另类老肥妇| 久久久在线观看| 成人精品久久av网站| 成人国产亚洲精品a区天堂华泰| 国产主播精品在线| 午夜精品一区二区三区在线| 国产精品毛片a∨一区二区三区|国| 国产精品精品久久久久久| 2020欧美日韩在线视频| 国产一区二区黑人欧美xxxx| 亚洲人成在线一二| 欧美电影免费播放| 国产亚洲精品va在线观看| 午夜精品福利在线观看| 韩国精品美女www爽爽爽视频| 国产精品久久久久福利| 欧美日韩国产影院| 久久久噜噜噜久久| 国内精品一区二区三区四区| 亚洲精品xxx| 日韩av电影在线播放| 91久久夜色精品国产网站| 久久久91精品国产| 日韩中文字幕精品| 欧美精品videos性欧美| 日本精品视频网站| 国产精品99导航| 欧美成人激情视频免费观看| 久久国产精品久久久久久久久久| 国产精品网址在线| 97av视频在线| 国产亚洲aⅴaaaaaa毛片| 成人乱人伦精品视频在线观看| 亚洲欧美精品一区| 成人午夜高潮视频| 成人网页在线免费观看| 亚洲精品91美女久久久久久久| 欧美日韩视频免费播放| 91亚洲精品一区二区| 欧美日韩免费观看中文| 亚洲第一网站免费视频| 欧美视频在线免费看| 久久国产精品偷| 夜夜嗨av一区二区三区四区| 伊人成人开心激情综合网| 亚洲国产精品女人久久久| 欧美日韩精品在线观看| 97成人精品视频在线观看| 亚洲天堂av高清| 久久天天躁狠狠躁夜夜爽蜜月| 成人黄色片网站| 欧美寡妇偷汉性猛交| 欧亚精品在线观看| 国产欧美久久久久久| 欧美在线观看视频| 亚洲精品网站在线播放gif| 日韩在线视频观看| 亚洲激情小视频| 国产精品一区二区三区久久久| 最近2019中文字幕mv免费看| 日韩电影免费在线观看中文字幕| 欧美黄色三级网站| 777国产偷窥盗摄精品视频| 国产精品高潮在线| 午夜精品www| 九九热r在线视频精品| 成人看片人aa| 91香蕉嫩草神马影院在线观看| www.欧美精品一二三区| 亚洲视频在线视频| www.日本久久久久com.| 色综合影院在线| 欧美黄色片免费观看| 久久久久久中文字幕| 日韩精品久久久久久久玫瑰园| 国产成人精品a视频一区www| 日韩国产欧美区| 国产精品美女免费看| 欧美视频专区一二在线观看| 欧美性猛交xxxx乱大交| 亚洲影院高清在线| 国产欧美日韩高清| 亚洲天堂成人在线视频| 北条麻妃在线一区二区| 国产精品视频自拍| 亚洲国产日韩欧美综合久久| 另类天堂视频在线观看| 日韩有码在线电影| 国产乱肥老妇国产一区二| 欧美色另类天堂2015| 亚洲国产精品高清久久久| 亚洲午夜av久久乱码| 亚洲a成v人在线观看| 欧美精品www在线观看| 亚洲国产另类 国产精品国产免费| 国产精品视频资源| 亚洲第一网站男人都懂| 日韩性xxxx爱| 亚洲精品久久久久久久久久久久久| 亚洲欧美一区二区三区情侣bbw| www.欧美免费| 欧美在线不卡区| 91精品一区二区| 亚洲国产精品推荐| 亚洲天堂2020| 中文字幕亚洲无线码a| 亚洲国产一区自拍| 久久网福利资源网站| 日韩欧美一区二区三区| 中文字幕av一区二区三区谷原希美| 搡老女人一区二区三区视频tv| 日韩精品免费在线| 国产成人精品免高潮费视频| 国产精品一区二区女厕厕| 欧美日韩国产999| 中文字幕欧美精品日韩中文字幕| 欧美成人亚洲成人日韩成人| 国内成人精品视频| 国产精品午夜视频| 亚洲国产精品久久久久秋霞不卡| 国产精品网站视频| 欧美在线中文字幕| 国产福利视频一区二区| 久久国产精品99国产精| 亚洲国产精品yw在线观看| 欧美国产视频一区二区| 亚洲日本中文字幕免费在线不卡| 久久久久久亚洲精品不卡| 精品福利在线视频| 亚洲高清久久久久久|