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

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

Mahmoud and a Dictionary codeforces396 div2 D

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

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在线播放资源| 日韩在线中文视频| 日本精品视频网站| 在线观看不卡av| 国产亚洲精品日韩| 亚洲自拍偷拍视频| 96国产粉嫩美女| 国产91色在线免费| 国产成人精品视频在线观看| 国产综合色香蕉精品| 久久婷婷国产麻豆91天堂| 成人欧美一区二区三区在线湿哒哒| 91久久精品在线| 日韩精品中文字| 97视频免费在线看| 欧美成人在线免费| 国内精品伊人久久| 日韩中文综合网| 亚洲成人黄色在线观看| 欧美亚洲视频一区二区| 欧美性生交大片免费| 成人福利网站在线观看| 久久亚洲影音av资源网| 欧美放荡办公室videos4k| 欧美大片免费观看| 国产精品视频永久免费播放| 欧美精品久久久久| 亚洲毛片在线看| 97国产在线观看| 久久久爽爽爽美女图片| 亚洲成人性视频| 国产日韩欧美影视| 成人福利在线观看| 亚洲天堂男人天堂女人天堂| 欧美一区二区三区艳史| 亚洲性av在线| 久久久精品一区二区三区| 日本a级片电影一区二区| 国产欧美精品日韩| 国产精品久久久久久中文字| 97精品一区二区三区| 欧美激情极品视频| 国产精品第8页| 午夜精品一区二区三区视频免费看| 国产精品久久久久影院日本| 亚洲精品少妇网址| 国产精品久久久精品| 亚洲sss综合天堂久久| 欧美另类xxx| 欧日韩在线观看| 亚洲另类激情图| 青青草成人在线| 亚洲男人天堂手机在线| 国产一区二中文字幕在线看| 久久夜色精品亚洲噜噜国产mv| 久久久久久久一区二区三区| 亚洲欧洲视频在线| 国产综合色香蕉精品| 91免费视频国产| 国产亚洲视频在线| 性夜试看影院91社区| 成人美女av在线直播| 久久久久久久国产精品| 国产精品入口免费视| 亚洲激情小视频| 狠狠做深爱婷婷久久综合一区| 欧美激情一区二区三区成人| 亚洲毛茸茸少妇高潮呻吟| 精品国产乱码久久久久酒店| 国产精品入口免费视| 欧美日韩色婷婷| 国产成人精品久久亚洲高清不卡| 伊人伊成久久人综合网站| 色先锋久久影院av| 国色天香2019中文字幕在线观看| 国产亚洲欧美日韩一区二区| 69av成年福利视频| 中文字幕精品影院| 欧美激情a∨在线视频播放| 久久精品国产欧美激情| 国产suv精品一区二区三区88区| 国产亚洲欧美aaaa| 欧美性猛交xxxx免费看久久久| 国产在线观看不卡| 国产精品爱啪在线线免费观看| 精品久久久久久久久久久久久久| 欧美一级大片在线免费观看| 国产91精品最新在线播放| 乱亲女秽乱长久久久| 亚洲肉体裸体xxxx137| 国产香蕉一区二区三区在线视频| 日韩av最新在线观看| 日韩在线视频免费观看高清中文| 亚洲性生活视频| 欧美一性一乱一交一视频| 久久精品久久久久久| 中文字幕亚洲一区二区三区| 91中文精品字幕在线视频| 国产精品狼人色视频一区| 国产精品小说在线| 91色在线视频| 成人妇女免费播放久久久| 国产精欧美一区二区三区| 国产美女久久精品香蕉69| 国产精品中文字幕久久久| 欧美怡春院一区二区三区| 国产不卡av在线| 成人免费午夜电影| 精品欧美激情精品一区| 57pao国产精品一区| 国内精品久久久久影院优| 中文字幕亚洲欧美日韩在线不卡| 欧美黄网免费在线观看| 久久久精品久久| 色综合色综合久久综合频道88| 欧美小视频在线观看| 国产精品v日韩精品| 亚洲欧洲在线免费| 日本电影亚洲天堂| 精品久久久国产精品999| 午夜精品久久久久久久白皮肤| 日韩av不卡在线| 欧美性猛交xxxx免费看漫画| 久久天天躁狠狠躁夜夜躁2014| 91av视频在线免费观看| 久久99精品久久久久久青青91| 亚洲一区二区国产| 韩剧1988免费观看全集| 欧美在线免费观看| 亚洲精品网站在线播放gif| 欧美成人四级hd版| 都市激情亚洲色图| 国产亚洲日本欧美韩国| 国产成人一区二区三区| 91午夜理伦私人影院| 亚洲天堂开心观看| 亚洲片在线资源| 日韩av一区在线| 久久频这里精品99香蕉| 国产精品久久久久久久久久三级| 久久影视电视剧免费网站清宫辞电视| 欧美国产日韩一区二区在线观看| 亚洲欧美国产精品久久久久久久| 九九热这里只有精品6| 一区二区三区天堂av| 日本在线观看天堂男亚洲| 国产丝袜高跟一区| 亚洲va欧美va在线观看| 欧美日韩国产黄| 亚洲国产古装精品网站| 性欧美激情精品| 日本一区二区在线播放| 欧美激情videos| 国产在线高清精品| 国产精品免费福利| 欧美日韩成人网| 国产一区二区三区在线免费观看| 91超碰中文字幕久久精品| 精品国产鲁一鲁一区二区张丽| 亚洲国产精品99久久| 亚洲一区二区三区在线免费观看| 茄子视频成人在线| 92国产精品久久久久首页| 青青久久aⅴ北条麻妃|