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

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

Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary(并查集)

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

D. Mahmoud and a Dictionary

time limit per test:4 seconds

memory limit per test:256 megabytes

input:standard input

output:standard 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表示是反義詞,如果是與之前矛盾的關系,輸出no,跳過本次,否則輸出yes。q次提問,兩個次數是同義的輸出1,反義輸出2,不知道輸出3. 題解:很經典的并查集。用2*i表示這個詞,2*i-1表示反義。并查集處理一下即可。 代碼:

#include <bits/stdc++.h>#define ll long longusing namespace std;const int N=1e5+10;int n,m,q,x;string str,a,b;map<string,int>mp;int pre[N<<1];int find(int x){ return x==pre[x]?x:pre[x]=find(pre[x]);}void mx(int x,int y){ x=find(x); y=find(y); if(x!=y) pre[x]=y;}int main(){ cin>>n>>m>>q; for(int i=1;i<=2*n;i++) pre[i]=i; for(int i=1;i<=n;i++) { cin>>str; mp[str]=i; } while(m--) { cin>>x>>a>>b; if(x==1) { if(find(mp[a]*2)==find(mp[b]*2-1)) { cout<<"NO"<<endl; continue; } else { cout<<"YES"<<endl; mx(mp[a]*2,mp[b]*2); mx(mp[a]*2-1,mp[b]*2-1); } } else { if(find(mp[a]*2)==find(mp[b]*2)) { cout<<"NO"<<endl; continue; } else { cout<<"YES"<<endl; mx(mp[a]*2,mp[b]*2-1); mx(mp[a]*2-1,mp[b]*2); } } } while(q--) { cin>>a>>b; if(find(mp[a]*2)==find(mp[b]*2)||find(mp[a]*2-1)==find(mp[b]*2-1)) cout<<"1"<<endl; else if(find(mp[a]*2)==find(mp[b]*2-1)||find(mp[a]*2-1)==find(mp[b]*2)) cout<<"2"<<endl; else cout<<"3"<<endl; } return 0;}
上一篇:r 常規

下一篇:POJ 3579 Median(2次二分)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
日韩av手机在线观看| 亚洲欧美综合另类中字| 色综合色综合久久综合频道88| 久久综合久久88| 黑人巨大精品欧美一区二区一视频| 亚洲精品久久视频| 国产香蕉精品视频一区二区三区| 欧美性猛交xxxx乱大交蜜桃| 国产精品日韩欧美综合| 欧美日韩在线免费观看| 久久国产精品久久国产精品| 欧美性xxxx在线播放| 亚洲免费成人av电影| 日av在线播放中文不卡| 国产日韩欧美在线| 欧美美女操人视频| 欧美激情一级欧美精品| 亚洲九九九在线观看| 亚洲理论片在线观看| 亚洲国产精品人久久电影| 国产午夜精品免费一区二区三区| 久久视频免费观看| 4438全国成人免费| 尤物精品国产第一福利三区| 精品无人区乱码1区2区3区在线| 91视频国产精品| 久99九色视频在线观看| 亚洲理论电影网| 亚洲国产日韩欧美在线图片| 欧美国产激情18| 一个色综合导航| 91久久精品美女| 有码中文亚洲精品| 欧美贵妇videos办公室| 欧美成人黄色小视频| 亚洲精品自拍第一页| 欧美黑人xxxⅹ高潮交| 成人淫片在线看| 久久久99免费视频| 亚洲精品www久久久| 久久久综合av| 国产精品国产福利国产秒拍| 国产精品99久久久久久人| 欧美精品在线网站| 欧美福利视频在线观看| 国产精品99久久久久久久久| 国产精品九九九| 日韩精品久久久久久福利| 国产欧美最新羞羞视频在线观看| 91精品国产91久久久久久久久| 国产主播喷水一区二区| 久热国产精品视频| 久久久久一本一区二区青青蜜月| 久久久国产精品免费| 中国china体内裑精亚洲片| 国产色视频一区| 国产精品久久久久久久av电影| 久久久久久久999精品视频| 国产在线精品成人一区二区三区| 日韩视频免费中文字幕| 亚洲第一男人天堂| 欧美大奶子在线| 日韩欧美在线观看| 久久久久久久影视| 久久婷婷国产麻豆91天堂| 日韩成人免费视频| 亚洲精品福利免费在线观看| 日韩国产激情在线| 国产精品爱久久久久久久| 97涩涩爰在线观看亚洲| 亚洲va久久久噜噜噜| 日韩中文字幕视频在线| 国产主播喷水一区二区| 亚洲人成电影网| 亚洲国产成人精品久久久国产成人一区| 91久久久久久| 久久亚洲精品视频| 另类少妇人与禽zozz0性伦| 久久久久久国产精品三级玉女聊斋| 美日韩精品视频免费看| 免费不卡在线观看av| 91精品国产乱码久久久久久蜜臀| 国产精品一区二区av影院萌芽| 国产精品视频最多的网站| 欧美制服第一页| 亚洲人成毛片在线播放| 2024亚洲男人天堂| 亚洲欧美日韩国产中文专区| 亚洲一区二区三区四区在线播放| 欧美激情第一页xxx| 久久九九热免费视频| 亚洲三级av在线| 精品国产精品自拍| 欧美大片在线看| 欧美视频在线看| 国产精品丝袜久久久久久不卡| 91久久在线观看| 人人澡人人澡人人看欧美| 欧美黑人巨大精品一区二区| 欧美国产日韩精品| 欧美—级高清免费播放| 欧美三级欧美成人高清www| 色视频www在线播放国产成人| 亚洲www永久成人夜色| 日韩视频精品在线| 久久国产视频网站| 国产亚洲精品一区二区| 97视频网站入口| 久久久久久久久电影| 亚洲一区中文字幕| 九九热99久久久国产盗摄| 亚洲国产成人精品电影| 欧美精品成人在线| 国产精品亚洲美女av网站| 成人黄色激情网| 欧美精品电影在线| 欧美疯狂做受xxxx高潮| 欧美大码xxxx| 秋霞av国产精品一区| 日韩视频免费大全中文字幕| 久久国产精彩视频| 亚洲国产精品成人一区二区| 中文字幕精品国产| 亚洲高清在线观看| 中文字幕在线国产精品| 亚洲欧美日韩一区在线| 伊人男人综合视频网| 欧美肥老妇视频| 91精品在线播放| 亚洲天天在线日亚洲洲精| 日韩中文理论片| 亚洲成人黄色网| 奇米成人av国产一区二区三区| 97在线视频一区| 中文字幕精品国产| 亚洲欧洲一区二区三区在线观看| 97久久精品在线| 美女av一区二区| 91免费高清视频| 欧美精品www| 欧美日韩在线看| 欧美不卡视频一区发布| 91高清在线免费观看| 亚洲视频电影图片偷拍一区| 韩曰欧美视频免费观看| 亚洲精品国产免费| 在线观看日韩视频| 亚洲福利视频免费观看| 日韩在线观看高清| 欧美性做爰毛片| 97视频人免费观看| 91久久精品久久国产性色也91| 国产99在线|中文| 中文字幕一区日韩电影| 亚洲欧洲中文天堂| 91精品国产91久久久久久不卡| 亚洲国产成人精品电影| 91情侣偷在线精品国产| 日本免费久久高清视频| 中文字幕日韩精品有码视频| 人人做人人澡人人爽欧美| 欧美精品久久久久久久免费观看| 亚洲精品国产免费| 国产精品旅馆在线|