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

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

Mahmoud and a Dictionary codeforces396 div2 D

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

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
国产精品美乳一区二区免费| 国产美女久久精品香蕉69| 久久久久国产精品免费| 亚洲国产精品成人va在线观看| 亚洲性69xxxbbb| 中文字幕亚洲欧美| 欧美日韩福利电影| 欧美激情在线播放| 欧美激情喷水视频| 国产成人精品a视频一区www| 日韩欧美国产网站| 中文国产成人精品久久一| 美女少妇精品视频| 欧美第一黄色网| 一区二区三欧美| 伊人久久大香线蕉av一区二区| 日本精品视频在线| 国模叶桐国产精品一区| 中文字幕久久亚洲| 日本成人免费在线| 色樱桃影院亚洲精品影院| 亚洲欧美中文另类| 久久精品中文字幕一区| 色一情一乱一区二区| 亚洲精品电影网站| 91久久精品日日躁夜夜躁国产| 九九精品视频在线| 日韩在线观看网站| 国模gogo一区二区大胆私拍| 91网站免费观看| 在线观看免费高清视频97| 蜜臀久久99精品久久久久久宅男| 国产日韩中文字幕在线| 国产在线观看不卡| 日韩在线中文字幕| 亚洲v日韩v综合v精品v| 啪一啪鲁一鲁2019在线视频| 91最新国产视频| 亚洲精品色婷婷福利天堂| 亚洲免费影视第一页| 亚洲三级 欧美三级| 91在线观看欧美日韩| 精品人伦一区二区三区蜜桃网站| 亚洲天堂第一页| 欧美高清无遮挡| 亚洲级视频在线观看免费1级| 国产一区二区精品丝袜| 久久久久久久色| 国产精品亚洲精品| 日韩精品丝袜在线| 福利视频一区二区| 日韩欧美在线视频| 亚洲无线码在线一区观看| 中文字幕亚洲图片| 日韩欧美高清视频| 51色欧美片视频在线观看| 欧美小视频在线观看| 中文字幕成人在线| 色妞久久福利网| 欧美日韩免费在线| 97视频在线观看免费高清完整版在线观看| 国产精品一区二区三区毛片淫片| 久久免费视频在线观看| 黄色成人av网| 亚洲专区中文字幕| 激情懂色av一区av二区av| 尤物九九久久国产精品的分类| 午夜精品一区二区三区av| 青青草99啪国产免费| 亚洲成人网在线观看| 国产一区二区视频在线观看| 欧美午夜久久久| 亚洲精品色婷婷福利天堂| 成人有码在线播放| 亚洲国产第一页| 久久九九亚洲综合| 久久综合电影一区| 日韩欧美a级成人黄色| 欧美在线观看日本一区| 欧美精品在线网站| 亚洲成色999久久网站| 日韩精品极品在线观看播放免费视频| 91国产视频在线播放| 97香蕉超级碰碰久久免费的优势| 国产做受69高潮| 精品国产一区二区三区久久狼黑人| 久久精品国产亚洲一区二区| 成人福利网站在线观看11| 日韩免费观看av| 中文字幕日韩高清| 久久久亚洲欧洲日产国码aⅴ| www.亚洲天堂| 亚洲国产精品va在线看黑人动漫| 精品日韩美女的视频高清| 中文字幕日本精品| 国产成人综合一区二区三区| 国产网站欧美日韩免费精品在线观看| 国产精品网红直播| 亚洲欧美变态国产另类| 亚洲精品中文字幕有码专区| 国产一区二区激情| 欧美日韩在线视频一区二区| 成人在线视频网| 成人性生交大片免费观看嘿嘿视频| 久久精品国产v日韩v亚洲| 欧美日韩裸体免费视频| 国产一区二区三区网站| 亚洲一区二区三区视频播放| 欧美巨大黑人极品精男| 欧美精品在线免费观看| 亚洲精品影视在线观看| 91精品国产色综合| 国产一区二区三区在线视频| 亚洲精品中文字幕有码专区| 久久99久久99精品中文字幕| 欧美视频中文在线看| 欧美电影免费观看电视剧大全| 国产97色在线|日韩| 中文字幕亚洲一区二区三区| 欧美激情区在线播放| 日韩在线视频网站| 欧美性一区二区三区| 91精品久久久久| 91久久在线播放| 亚洲黄色www| 国产精品久久不能| 热门国产精品亚洲第一区在线| 中文字幕日韩欧美精品在线观看| 亚洲第一精品电影| 久久精品国产欧美激情| 欧美www在线| 欧美成人精品h版在线观看| 欧美视频专区一二在线观看| 一区二区三区视频在线| 国内精品久久久久久影视8| 国产精品1区2区在线观看| 欧美大尺度激情区在线播放| 91免费看国产| 高清在线视频日韩欧美| 91九色国产社区在线观看| 欧美性视频在线| 精品久久久国产精品999| 中文字幕av日韩| 久久精品精品电影网| 伊人久久五月天| 日本高清视频一区| 亚洲丁香久久久| 日韩亚洲在线观看| 国产va免费精品高清在线| 日韩欧美在线视频日韩欧美在线视频| 韩剧1988免费观看全集| 成人免费视频在线观看超级碰| 色综合久久精品亚洲国产| 性夜试看影院91社区| 日韩视频第一页| 激情久久av一区av二区av三区| 欧美裸体xxxxx| 欧美自拍视频在线| 亚洲欧美第一页| 中日韩美女免费视频网址在线观看| 亚洲人成在线免费观看| 美女国内精品自产拍在线播放| 国产精品入口免费视频一| 久久伊人91精品综合网站|