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

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

D. Mahmoud and a Dictionary

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

D. Mahmoud and a Dictionarytime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard 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 nm and q (2?≤?n?≤?105, 1?≤?m,?q?≤?105) where n is the number of words in the dictionary, mis 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.

Examplesinput
3 3 4hate love like1 love like2 love hate1 hate likelove likelove hatelike hatehate likeoutput
YESYESNO1222input
8 6 5hi welcome hello ihateyou goaway dog cat rat1 hi welcome1 ihateyou goaway2 hello ihateyou2 hi goaway2 hi hello1 hi hellodog catdog hihi helloihateyou goawaywelcome ihateyououtput
YESYESYESYESNOYES33112

嗯,帶權并查集的應用。沒有學習過帶權并查集的可以先看下這里:

http://blog.csdn.net/harlow_cheng/article/details/52737486

然后就沒什么多說的了。就兩種關系,應該說是比較基本的。

#include <bits/stdc++.h>using namespace std;int n,m,q;const int MAXN=1e5+7;const int mod=1e9+7;int pre[MAXN],relation[MAXN];map<string,int>num;string s1,s2;int findx(int x){    if(pre[x]==x)    {        return x;    }    int order=pre[x];    pre[x]=findx(pre[x]);    relation[x]=(relation[x]+relation[order])%2;    return pre[x];}int main(){    int i;    scanf("%d%d%d",&n,&m,&q);    for(i=0;i<n;++i)    {        cin>>s1;        num[s1]=i;    }    for(i=0;i<n;++i)    {        pre[i]=i;        relation[i]=0;    }    int x,y,z;    while(m--)    {        cin>>z>>s1>>s2;        z--;        x=num[s1],y=num[s2];        int a=findx(x),b=findx(y);        if(a!=b)//關系還沒有建立過        {            puts("YES");            //更新結點值            pre[b]=a;            relation[b]=(relation[x]-relation[y]+z+2)%2;        }        else//關系已經建立        {            int p=(relation[x]-relation[y]+2)%2;//得到關系            if(p==z)puts("YES");            else puts("NO");        }    }    while(q--)    {        cin>>s1>>s2;        x=num[s1];        y=num[s2];        int a=findx(x),b=findx(y);        if(a!=b)puts("3");//沒建立過聯系        else        {            int p=(relation[x]-relation[y]+2)%2;            printf("%d/n",p+1);        }    }}


上一篇:mybatis 打印sql執行語句

下一篇:poj1936

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产精品69久久| 狠狠色噜噜狠狠狠狠97| 色噜噜狠狠狠综合曰曰曰88av| 亚洲一区999| 日本一区二区三区在线播放| 亚洲图片欧美日产| 久久频这里精品99香蕉| 中文字幕日韩视频| 精品高清美女精品国产区| 精品免费在线视频| 91黑丝高跟在线| 91在线高清免费观看| 啪一啪鲁一鲁2019在线视频| 中文字幕欧美精品在线| 国内成人精品视频| 欧美激情女人20p| 欧洲s码亚洲m码精品一区| 国产精品视频中文字幕91| 国内精品小视频| 日韩成人av网| 91国内精品久久| 亚洲第一精品电影| 国产一区香蕉久久| 国产精品成熟老女人| 秋霞午夜一区二区| 疯狂做受xxxx欧美肥白少妇| 国产精品99蜜臀久久不卡二区| 亚洲成人性视频| 亚洲福利在线看| 久久免费少妇高潮久久精品99| 日韩视频在线一区| 国产精品黄色影片导航在线观看| 7777免费精品视频| 91人成网站www| 日日骚av一区| 色综合久久天天综线观看| 成人精品在线视频| 91在线网站视频| 国产欧美一区二区三区久久| 午夜剧场成人观在线视频免费观看| 久久免费视频观看| 欧美性视频网站| 亚洲自拍偷拍一区| 性欧美xxxx视频在线观看| 成人午夜激情免费视频| 欧美性猛交丰臀xxxxx网站| 精品国产老师黑色丝袜高跟鞋| 91在线网站视频| 91九色视频导航| 久久亚洲精品视频| 国产丝袜一区二区三区| 精品国产户外野外| 日韩av在线影院| 一区二区三区 在线观看视| 日本亚洲欧美成人| 日本人成精品视频在线| 欧美一级片免费在线| 日韩国产欧美区| 97热在线精品视频在线观看| 粉嫩老牛aⅴ一区二区三区| 欧美日本中文字幕| 黄色成人av网| 国产精品一二三视频| 久久久久久亚洲精品中文字幕| 精品亚洲va在线va天堂资源站| 3344国产精品免费看| 综合国产在线视频| 久久综合久久美利坚合众国| 午夜伦理精品一区| 成人激情综合网| 色综合天天综合网国产成人网| 国产精品久久久久免费a∨| 亚洲偷欧美偷国内偷| 韩国精品美女www爽爽爽视频| 亚洲精品成人久久| 亚洲四色影视在线观看| 狠狠色狠狠色综合日日小说| 成人福利网站在线观看| 精品久久久久久亚洲精品| 久久亚洲电影天堂| 国产一区二中文字幕在线看| 亚洲精品久久久一区二区三区| 日韩免费不卡av| 97热在线精品视频在线观看| 国模精品视频一区二区| 成人免费网站在线| 亚洲成人av片在线观看| 中文字幕国产精品久久| 日本在线精品视频| 国产在线观看91精品一区| 韩剧1988在线观看免费完整版| 国产盗摄xxxx视频xxx69| 91精品视频一区| 国产精品美女免费| 亚洲永久在线观看| 国产精品www色诱视频| 国产精品美乳在线观看| 国产精品夜间视频香蕉| 国产成人一区二区| 九色成人免费视频| 国产免费一区二区三区香蕉精| 久久这里有精品| 18一19gay欧美视频网站| 亚洲最大激情中文字幕| 国产精品久久久久高潮| 在线播放精品一区二区三区| 国产精品欧美日韩一区二区| 欧美裸身视频免费观看| 红桃视频成人在线观看| 成人免费网站在线看| 亚洲91精品在线观看| 国产成人精品久久| 日韩精品在线视频美女| 亚洲成人激情在线观看| 欧美成人一区在线| 国产精品91久久久久久| 亚洲成人av在线| 国产精品成人一区二区三区吃奶| 亚洲精品美女在线观看播放| 青青青国产精品一区二区| 午夜伦理精品一区| 日韩在线不卡视频| 国产成人jvid在线播放| 日本视频久久久| 亚洲二区在线播放视频| 欧美日韩xxxxx| 国产91精品久| 欧美另类交人妖| 日本亚洲欧洲色| 亚洲一区二区三区毛片| 国产91久久婷婷一区二区| 久久精品成人欧美大片| 国产精品美乳一区二区免费| 亚洲性无码av在线| 日韩电影中文字幕av| 欧美激情videos| 操91在线视频| 91网站免费看| 亚洲伊人第一页| 日韩欧美国产视频| 美女av一区二区| 国产一区二区欧美日韩| 欧美另类老肥妇| 国产欧美一区二区白浆黑人| 色婷婷综合久久久久中文字幕1| 欧美夜福利tv在线| 高清视频欧美一级| 国产欧美日韩免费看aⅴ视频| 久久精品视频导航| 大伊人狠狠躁夜夜躁av一区| 亚洲精品国产综合久久| 欧美一级高清免费播放| 日韩欧美一区二区三区| 国产一区二区三区丝袜| 成人在线免费观看视视频| 中文字幕在线日韩| 亚洲aⅴ男人的天堂在线观看| 国产精品第100页| 91精品久久久久久久久久久久久久| 亚洲第一精品夜夜躁人人躁| 日韩av免费在线| 一个色综合导航| 国产噜噜噜噜噜久久久久久久久| 国产精品18久久久久久麻辣|