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

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

D. Mahmoud and a Dictionary

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

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
国产精品a久久久久久| 亚洲久久久久久久久久久| 亚洲国内精品在线| 九九视频这里只有精品| 亚洲男人天堂手机在线| 欧美中文字幕在线| 国产精品美女免费看| 亚洲免费视频网站| 国产精品亚洲欧美导航| 久久免费在线观看| 欧美日韩免费网站| 日韩欧美亚洲范冰冰与中字| 国产精品电影久久久久电影网| 欧美插天视频在线播放| 久久精品亚洲精品| 久久视频在线直播| 欧美日本高清一区| 日韩高清a**址| 一区二区三区 在线观看视| 日韩不卡在线观看| 热门国产精品亚洲第一区在线| 欧美日韩在线视频一区| 国产精品露脸av在线| 成人在线激情视频| 亚洲成人黄色网址| 91精品啪在线观看麻豆免费| 久久亚洲国产成人| 黑人巨大精品欧美一区二区| 亚洲国产精品yw在线观看| 国产精品第一区| 久久手机免费视频| 欧美成人高清视频| 久久福利视频网| 亚洲毛片一区二区| 国产精品一区av| 亚洲欧美在线x视频| 亚洲图片欧洲图片av| 日韩av手机在线| 成人网在线视频| 欧美性猛交xxxx黑人猛交| 久久精品中文字幕一区| 国产精品高潮呻吟久久av野狼| 亚洲男人天堂久| 91在线色戒在线| 欧美乱人伦中文字幕在线| 欧美老女人性生活| 伊人青青综合网站| 日韩免费观看在线观看| 日韩免费视频在线观看| 午夜精品久久久久久久99黑人| 国产偷亚洲偷欧美偷精品| 亚洲精品乱码久久久久久金桔影视| 国产在线观看精品| 久久精品国产91精品亚洲| 日韩精品一区二区三区第95| 国外成人免费在线播放| 亚洲精品久久久久中文字幕欢迎你| 国产精品成人aaaaa网站| 91理论片午午论夜理片久久| 日韩高清电影免费观看完整版| 日韩中文字幕在线精品| 亚洲成色777777在线观看影院| 久久精品小视频| 亚洲欧美综合另类中字| 日韩欧美中文第一页| 精品国产一区二区三区久久久狼| 亚洲人成77777在线观看网| 国产亚洲视频中文字幕视频| 九九热视频这里只有精品| 亚洲国产精品女人久久久| 日韩欧美a级成人黄色| 亚洲第一精品久久忘忧草社区| 成人xvideos免费视频| 亚洲国产天堂久久综合网| 国产亚洲欧美日韩一区二区| 欧美久久精品一级黑人c片| 国产精品成人aaaaa网站| 国产精品www色诱视频| 精品国产精品三级精品av网址| 亚洲男人天堂2019| 国产精品网站视频| 亚洲片国产一区一级在线观看| 久久久久久亚洲精品不卡| 国产精品久久久久一区二区| 亚洲国产精品电影在线观看| 国产精品视频在线播放| 91亚洲精品久久久久久久久久久久| 亚洲免费影视第一页| 亚洲有声小说3d| 久久精品国产69国产精品亚洲| 久久人人爽人人爽人人片av高请| 亚洲精品久久久久久久久久久| 国产一区二区三区毛片| 亚洲精品国产拍免费91在线| 色悠悠国产精品| 久久久久日韩精品久久久男男| 国产午夜精品视频免费不卡69堂| 超薄丝袜一区二区| 国内外成人免费激情在线视频网站| 日韩一区视频在线| 国产一区红桃视频| 色偷偷亚洲男人天堂| 久久人人爽人人爽人人片av高请| 色综合伊人色综合网站| 亚洲综合色激情五月| 久久视频在线直播| 欧美极品在线播放| 亚洲天堂免费观看| 欧美一级淫片videoshd| 亚洲欧洲国产一区| 午夜精品蜜臀一区二区三区免费| 自拍偷拍亚洲区| 欧美黑人巨大精品一区二区| 欧美日韩亚洲视频一区| 在线色欧美三级视频| 国产精品1234| 欧美一区二区大胆人体摄影专业网站| 久久久久久亚洲精品| 日韩国产欧美区| 日韩欧美国产免费播放| 亚洲国产又黄又爽女人高潮的| 精品偷拍各种wc美女嘘嘘| 欧美劲爆第一页| 中文字幕av一区二区| 国模叶桐国产精品一区| 成人有码在线播放| 在线播放日韩精品| 宅男66日本亚洲欧美视频| 国产精品一区专区欧美日韩| 亚洲精品久久久久中文字幕二区| 伊人久久久久久久久久久久久| 亚洲色图25p| 欧美有码在线观看| 欧美一区视频在线| 一区二区三区黄色| 日本乱人伦a精品| 国产精品稀缺呦系列在线| 日韩视频在线免费| 日本国产欧美一区二区三区| 日韩a**中文字幕| 在线观看日韩专区| 国产日韩欧美在线观看| 亚洲va久久久噜噜噜| 91老司机精品视频| 欧美精品一本久久男人的天堂| 亚洲欧美中文字幕| 中文字幕精品一区二区精品| 国产精品一区二区在线| 亚洲精品wwwww| 国产美女精品视频免费观看| 欧美激情2020午夜免费观看| 91在线观看免费| 国产精品稀缺呦系列在线| 久久这里有精品视频| 国产精品入口免费视频一| 日韩欧美极品在线观看| 欧美一级在线播放| 国产999在线观看| 欧洲精品久久久| 久久综合五月天| 欧美一区二区大胆人体摄影专业网站| 97超视频免费观看| 欧美成人高清视频| 91热精品视频|