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

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

D. Mahmoud and a Dictionary

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

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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
久久精品国产69国产精品亚洲| 欧美放荡办公室videos4k| 亚洲人成电影网站色…| 久久久视频免费观看| 亚洲二区在线播放视频| 亚洲毛片一区二区| 日韩欧美在线免费观看| 91精品久久久久久久久久另类| 日本精品一区二区三区在线播放视频| 国产精品88a∨| 亚洲另类图片色| 精品一区二区三区四区在线| 国产精品第七十二页| 国产精品成人一区二区三区吃奶| 久久久精品免费视频| 欧美精品在线第一页| 午夜精品一区二区三区视频免费看| 911国产网站尤物在线观看| 国产成人精品久久亚洲高清不卡| 久久成年人免费电影| 亚洲精品丝袜日韩| 国产精品久久久久久久天堂| 亚洲另类欧美自拍| 国产日本欧美一区二区三区| 毛片精品免费在线观看| 清纯唯美亚洲激情| 久久精品国产清自在天天线| 欧美成人精品激情在线观看| 精品少妇v888av| 成人一区二区电影| 精品国产一区久久久| 疯狂做受xxxx高潮欧美日本| 亚洲第一福利视频| 欧美性生交大片免网| 色先锋久久影院av| 国产精品青草久久久久福利99| 国产精品久久久久久久av大片| 久久久噜噜噜久噜久久| 精品一区二区三区电影| 91精品国产91久久| 精品久久久久久亚洲精品| 欧美午夜性色大片在线观看| 国产精品av在线播放| 亚洲国产精品久久| 丰满岳妇乱一区二区三区| 福利视频一区二区| 国产精品免费看久久久香蕉| 欧美中文在线字幕| 色偷偷888欧美精品久久久| 亚洲国产高潮在线观看| 中文字幕欧美日韩在线| 国产精品丝袜视频| 国产亚洲一区精品| 国产一区二区丝袜| 久久久久国产精品免费网站| 97国产精品人人爽人人做| 国产精品久久久久久久久免费看| 欧美视频一二三| 亚洲午夜精品久久久久久久久久久久| 人妖精品videosex性欧美| 久久久999精品| 亚洲在线观看视频| 57pao成人永久免费视频| 日韩av一区二区在线观看| 亚洲激情电影中文字幕| 91国产视频在线| 日韩最新免费不卡| 亚洲美女激情视频| 欧美亚洲视频在线观看| 亚洲综合中文字幕在线| 久久色免费在线视频| 亚洲午夜精品视频| 九九热在线精品视频| 亚洲黄色免费三级| 91性高湖久久久久久久久_久久99| 欧美精品制服第一页| 日韩在线欧美在线国产在线| 欧美大成色www永久网站婷| 国产精品十八以下禁看| 日韩av影视在线| 久久久亚洲影院你懂的| 亚洲欧美精品一区二区| 亚洲新中文字幕| 97欧美精品一区二区三区| 日韩有码在线播放| 国产成人一区二区| 亚洲天堂成人在线视频| 国产欧美日韩91| 亚洲资源在线看| 国产精品男女猛烈高潮激情| 91精品久久久久久久久不口人| 欧美整片在线观看| 亚洲综合国产精品| 69久久夜色精品国产7777| 欧美成人免费全部观看天天性色| 一区二区成人精品| 中文字幕日韩综合av| 亚洲欧美日韩国产中文| 日韩精品电影网| 成人av色在线观看| 亚洲国产欧美日韩精品| 欧美精品第一页在线播放| 热久久美女精品天天吊色| 精品久久中文字幕久久av| 欧美激情videos| 国产成人+综合亚洲+天堂| 欧美专区在线观看| 狠狠躁夜夜躁人人躁婷婷91| 一区二区三区视频在线| 日韩欧美一区二区三区久久| 亚洲www永久成人夜色| 91在线视频免费| 7m第一福利500精品视频| 91精品国产乱码久久久久久久久| 国产成人免费av电影| 久久乐国产精品| 91精品免费视频| 亚洲女人被黑人巨大进入| 欧美孕妇与黑人孕交| 国语自产偷拍精品视频偷| 免费97视频在线精品国自产拍| 在线观看精品自拍私拍| 欧美大荫蒂xxx| 国产丝袜视频一区| 成人国产精品日本在线| 91九色单男在线观看| 国产精品视频公开费视频| 欧美二区乱c黑人| 欧美在线影院在线视频| 国产91精品网站| 欧美午夜宅男影院在线观看| 亚洲aⅴ男人的天堂在线观看| 久久资源免费视频| 欧美成人午夜激情| 一本大道亚洲视频| 欧美午夜激情视频| 国产成人综合久久| 亚洲最大成人网色| www.欧美免费| 国产免费亚洲高清| 日韩激情视频在线| 日本一区二区不卡| 欧美又大又硬又粗bbbbb| 久久久亚洲网站| 粉嫩老牛aⅴ一区二区三区| 色噜噜狠狠狠综合曰曰曰88av| 91免费电影网站| 人人做人人澡人人爽欧美| 亚洲综合成人婷婷小说| 欧美一区二区三区图| 国产91ⅴ在线精品免费观看| 国产精品亚洲一区二区三区| 亚洲国产美女久久久久| 欧美一区二区.| 欧美日韩国产中文字幕| 91国偷自产一区二区三区的观看方式| 久久精品久久久久久国产 免费| 精品视频—区二区三区免费| 亚洲精品一区二区三区不| 国产精品久久久久久久久粉嫩av| 国产精品永久免费在线| 久久久免费精品视频| 91久久综合亚洲鲁鲁五月天| 日韩一区二区三区在线播放|