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

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

D. Mahmoud and a Dictionary

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

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);        }    }}


上一篇:回文判斷

下一篇:Create Window

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产日韩欧美在线视频观看| 日韩免费在线播放| 日韩精品免费一线在线观看| 2019中文字幕在线| 日韩国产高清视频在线| 久久久久久久一区二区三区| 国产色婷婷国产综合在线理论片a| 韩国精品美女www爽爽爽视频| 在线观看不卡av| 国产精品美女av| 色诱女教师一区二区三区| 国产精品亚洲美女av网站| 丝袜亚洲另类欧美重口| 色一情一乱一区二区| 亚洲黄色免费三级| 亚洲精品电影久久久| 亚洲精品资源美女情侣酒店| 欧洲成人在线视频| 亚洲精品中文字幕女同| 亚洲欧美视频在线| 91久久在线视频| 成人久久久久爱| 精品成人久久av| 91精品久久久久久久| 欧美日韩国产第一页| 亚洲成人黄色网| 蜜臀久久99精品久久久无需会员| 国产精品成人av在线| 日韩美女主播视频| 国产欧美 在线欧美| 亚洲第一精品久久忘忧草社区| 日韩在线资源网| 国产精品视频区1| 日韩精品免费视频| 亚洲va电影大全| 亚洲天堂开心观看| 欧美大片大片在线播放| 亚洲精品国产精品国自产观看浪潮| 在线成人免费网站| 国产精品久久一| 亚洲电影第1页| 亚洲性无码av在线| 亚洲a在线观看| 亚洲精品www久久久| 欧美精品一区三区| 欧美另类老女人| 一区二区三区www| 在线观看不卡av| 精品国产乱码久久久久酒店| 欧美极品少妇xxxxⅹ免费视频| 国产精品入口日韩视频大尺度| 国产精品xxxxx| 日韩欧美成人免费视频| 黑人狂躁日本妞一区二区三区| 欧美精品videos另类日本| 日韩av中文字幕在线播放| 欧美精品videos性欧美| 欧美午夜激情在线| 成人欧美一区二区三区黑人孕妇| 国产91精品黑色丝袜高跟鞋| 91日本在线视频| 欧美成人黄色小视频| 久久频这里精品99香蕉| 亚洲女人天堂色在线7777| 韩国国内大量揄拍精品视频| 日韩欧美中文字幕在线观看| 国产午夜精品一区二区三区| 国产中文字幕91| 日韩欧美国产高清91| 国产成人精品视频在线观看| 欧美诱惑福利视频| 日韩精品免费观看| 久久天天躁狠狠躁夜夜躁2014| 欧美高清不卡在线| 欧美成人在线网站| 欧美午夜激情视频| 亚洲男人第一av网站| 亚洲国产小视频在线观看| 欧美日韩在线视频一区| 亚洲二区中文字幕| 色婷婷av一区二区三区久久| 中文字幕久久精品| 日韩精品视频免费专区在线播放| 久久久久久久电影一区| 亚洲激情自拍图| 午夜精品久久久久久久白皮肤| 久久夜色精品国产| 中文字幕日韩在线播放| 精品无码久久久久久国产| 亚洲最新中文字幕| 中文字幕亚洲色图| 日韩精品极品在线观看播放免费视频| 一区二区三区在线播放欧美| 亚洲精品电影在线观看| 日韩av最新在线| 久久露脸国产精品| 日韩精品视频免费在线观看| 国产精品第一第二| 在线一区二区日韩| 久久久久久69| 久久97精品久久久久久久不卡| 久久久久亚洲精品成人网小说| 中国日韩欧美久久久久久久久| 成人精品久久av网站| 欧美在线视频播放| 国产欧美一区二区三区在线| 日韩在线视频导航| 欧美电影免费观看网站| 狠狠色狠色综合曰曰| 国产精品网址在线| 亚洲精品wwww| 欧美高清在线播放| 欧美大成色www永久网站婷| 国产一区二区三区网站| 亚洲欧美激情一区| 羞羞色国产精品| 亚洲欧美一区二区三区情侣bbw| 国产精品88a∨| 美女av一区二区| 亚洲男人的天堂在线| 欧美黑人xxxⅹ高潮交| 亚洲一区二区三区视频| 国产视频观看一区| 日产精品久久久一区二区福利| 91精品国产电影| 日韩精品极品在线观看播放免费视频| 欧美丰满片xxx777| 久久亚洲私人国产精品va| 久久99久久久久久久噜噜| 国产在线观看精品| 国产精品亚洲第一区| 亚洲天堂av在线免费观看| 亚洲国产精品悠悠久久琪琪| 懂色av中文一区二区三区天美| 国产一区视频在线| 国产精品视频自在线| 91po在线观看91精品国产性色| 国产国语刺激对白av不卡| 亚洲新声在线观看| 国产精品久久999| 国产美女久久精品香蕉69| 国产成人精品视频在线| 深夜成人在线观看| 欧美亚洲国产视频| 日韩精品福利在线| 国产日产欧美精品| 91精品国产自产在线观看永久| 日韩精品黄色网| 国产精品美乳在线观看| 亚洲欧美日韩天堂| 欧美精品一区在线播放| 77777亚洲午夜久久多人| 国产日韩中文字幕在线| 成人国产精品一区| 欧美久久精品午夜青青大伊人| 久久久久久久久久久免费| 夜夜嗨av色综合久久久综合网| 欧美日韩中文字幕日韩欧美| 日韩av快播网址| 国产视频精品一区二区三区| 亚洲一区二区三区视频| 欧美日本高清视频| 久久影院资源网| 欧美亚洲午夜视频在线观看|