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

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

Mahmoud and a Dictionary codeforces396 div2 D

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

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电影在线观看| 亚洲精品久久久久中文字幕欢迎你| 国产精品国产福利国产秒拍| 欧美激情国产精品| 日韩在线国产精品| 91手机视频在线观看| 亚洲另类欧美自拍| 成人在线观看视频网站| 亚洲精品久久在线| 韩国福利视频一区| 欧美性黄网官网| 久久视频在线观看免费| 一区二区欧美亚洲| 欧美高清视频在线观看| 在线电影中文日韩| 久久天天躁狠狠躁老女人| 日韩av在线影视| 国产成人精品优优av| 深夜精品寂寞黄网站在线观看| 欧美成人一区在线| 亚洲国产精久久久久久| 亚洲999一在线观看www| 国产日韩精品在线| 日韩欧美精品免费在线| 国产精品高清网站| 亚洲精品av在线播放| 国产精品v日韩精品| 国产精品久久久久久搜索| 久久99精品久久久久久噜噜| 午夜精品久久久久久久男人的天堂| 亚洲深夜福利视频| 韩国三级电影久久久久久| 精品一区二区三区电影| 欧美日韩aaaa| 欧美日韩中文在线观看| 亚洲电影免费观看高清| 国产成人免费av| 中文字幕精品一区二区精品| 久久久久久免费精品| 国产精品视频久久久| 欧美激情视频在线| 最新亚洲国产精品| 亚洲欧美一区二区三区在线| 成人a视频在线观看| 国产日韩欧美夫妻视频在线观看| 亚洲欧美日本另类| 国产精品久久久久久久一区探花| 欧美午夜精品伦理| 91香蕉电影院| 亚洲国产毛片完整版| 欧美风情在线观看| 国产有码一区二区| 国产成人在线一区| 亚洲第一页中文字幕| 亚洲情综合五月天| 琪琪第一精品导航| 日韩欧美一区二区在线| 最近中文字幕日韩精品| 色中色综合影院手机版在线观看| 久久亚洲精品中文字幕冲田杏梨| 亚洲一区二区三区视频播放| 日韩欧美成人免费视频| 欧美成人免费在线视频| 性色av一区二区三区在线观看| 亚洲国产精品久久91精品| 中文字幕在线看视频国产欧美| 久久69精品久久久久久久电影好| 日韩欧美亚洲范冰冰与中字| 一本一本久久a久久精品牛牛影视| 国产丝袜视频一区| 日韩高清电影免费观看完整| 亚洲人精品午夜在线观看| 久久综合久中文字幕青草| www.亚洲天堂| 亚洲专区在线视频| 揄拍成人国产精品视频| 国产一区二区三区欧美| 国产欧美日韩91| 狠狠色香婷婷久久亚洲精品| 久久人人爽人人爽人人片av高请| 91精品国产99| 日本精品久久中文字幕佐佐木| 色爱av美腿丝袜综合粉嫩av| 久久久久久久一| 亚洲精品视频免费在线观看| 午夜精品久久久久久久白皮肤| 久久99亚洲热视| 成人av在线亚洲| 国产精品一区二区三区在线播放| 国产日韩欧美视频| 日日噜噜噜夜夜爽亚洲精品| 亚洲欧美三级在线| www欧美日韩| 国产免费成人av| 亚洲欧洲一区二区三区久久| 久国内精品在线| 超碰97人人做人人爱少妇| 国产成人高清激情视频在线观看| 91精品视频免费| 97在线精品视频| 欧美日韩在线观看视频小说| 久久精品国产99国产精品澳门| 国产精品久久久久久久久久免费| 2019亚洲男人天堂| 国内外成人免费激情在线视频| 亚洲精品网站在线播放gif| 欧美激情xxxx性bbbb| 这里只有视频精品| 91av在线网站| 国产精品高清在线观看| 欧美日韩精品在线观看| 亚洲精品中文字幕女同| 国产精品激情av在线播放| 91视频-88av| 亚洲一区二区在线播放| 国产精品美女www爽爽爽视频| 亚洲最大av网站| 日韩一区二区福利| 成人黄色片网站| 最近的2019中文字幕免费一页| 精品人伦一区二区三区蜜桃网站| 日韩男女性生活视频| 日韩精品视频三区| 欧美日本高清视频| 国内久久久精品| 97国产在线视频| 日韩欧美在线一区| 欧美午夜女人视频在线| 国产精品久久久久久中文字| 亚洲第一区第一页| 久久精品视频在线观看| 亚洲精品成人久久| 一本色道久久88综合日韩精品| 成人有码在线视频| 亚洲亚裔videos黑人hd| 九九热99久久久国产盗摄| 亚洲亚裔videos黑人hd| 高清一区二区三区日本久| 在线观看欧美日韩| 久久av红桃一区二区小说| 日韩精品视频在线播放| 日韩欧美综合在线视频| 日韩中文在线中文网三级| 91中文字幕在线| 欧美视频免费在线| 国产欧美精品一区二区三区-老狼| 色先锋久久影院av| 欧美日韩一区二区三区| 欧美极品欧美精品欧美视频| 国产精品视频中文字幕91| 日韩欧美亚洲综合| 亚洲男人天堂九九视频| 成人精品aaaa网站| 日本精品视频在线观看| 国产精品久久久久久久久粉嫩av| 91精品久久久久久久久|