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

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

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

2019-11-10 16:58:14
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
欧美中文字幕视频在线观看| 91av在线看| 粉嫩av一区二区三区免费野| 欧美性生交大片免费| 亚洲91av视频| 亚洲曰本av电影| 亚洲一区二区国产| 国产精品久久久久久久久久尿| 国产97在线亚洲| 欧美亚洲第一页| 国产精品久久久久久久久粉嫩av| 久久在线观看视频| 久久久久女教师免费一区| 日韩精品中文字幕视频在线| 国产日韩欧美视频| 亚洲毛片一区二区| 精品国内产的精品视频在线观看| 久久精品99久久久香蕉| 7777精品久久久久久| 日本亚洲欧洲色| 亚洲曰本av电影| 色午夜这里只有精品| 国产精品久久av| 久热精品视频在线| 亚洲视频axxx| 国产一区av在线| 久久天堂av综合合色| 最近2019中文字幕一页二页| 日韩美女免费观看| 国产欧美日韩91| 久久天天躁狠狠躁夜夜av| 最新69国产成人精品视频免费| 97香蕉久久超级碰碰高清版| 亚洲开心激情网| 欧美综合国产精品久久丁香| 久久久国产一区二区| 久久香蕉精品香蕉| 久久久亚洲网站| 成人美女av在线直播| 亚洲精品欧美日韩| 国产欧美精品va在线观看| 亚洲一区久久久| 亚洲国产黄色片| 久久亚洲精品成人| 国产亚洲精品综合一区91| 日韩欧美在线视频观看| 国产精品网红福利| 色999日韩欧美国产| 国内精品小视频在线观看| 日韩精品亚洲视频| 色综合视频一区中文字幕| 亚洲第一福利网| 亚洲天堂av电影| 亚洲欧洲美洲在线综合| 国产午夜精品视频| 国产91露脸中文字幕在线| 日韩欧美国产免费播放| 久久精品视频va| 国产区精品在线观看| 国产日本欧美一区二区三区在线| 久久精品久久久久久国产 免费| 久久久久久久久国产精品| 国产精品日日摸夜夜添夜夜av| 欧美日韩亚洲精品内裤| 国产成人精品免费视频| 日韩一区二区欧美| 亚洲国产成人精品久久久国产成人一区| 美女国内精品自产拍在线播放| 欧美性猛交xxxx黑人| 欧美性猛交xxxx黑人| 国产欧美一区二区三区在线| 日韩免费看的电影电视剧大全| 揄拍成人国产精品视频| 91情侣偷在线精品国产| 国产精品成人一区二区三区吃奶| 久久伊人色综合| 国产精品成人免费视频| 日韩av在线看| 日本久久久久久久久久久| 久久在精品线影院精品国产| 欧美最猛性xxxxx免费| 成人激情电影一区二区| 国产精品久久久久久久久久小说| 久久久国产精品免费| 国产成人免费91av在线| 色偷偷偷亚洲综合网另类| 91日本在线视频| 久久久久中文字幕| 久久国产精品久久久久久久久久| 亚洲国产精品成人av| 国产欧美在线看| 精品女同一区二区三区在线播放| 91视频-88av| 国产一区二区三区免费视频| 992tv成人免费视频| 亚洲热线99精品视频| 亚洲视频在线观看视频| 欧美日韩高清在线观看| 日韩在线免费高清视频| 国产精品三级在线| 国产精品一区二区久久久久| 精品中文字幕久久久久久| 亚洲r级在线观看| 久久亚洲精品国产亚洲老地址| 欧美综合在线观看| 亚洲一区二区久久久久久| 成人激情视频小说免费下载| 亚洲精品国产精品国产自| 亚洲精品456在线播放狼人| 日韩av综合网| 91系列在线播放| 亚洲美女www午夜| 永久免费毛片在线播放不卡| 欧美国产乱视频| 欧美性xxxx极品hd欧美风情| 亚洲天堂免费视频| 国产精品亚洲片夜色在线| 久久手机精品视频| 亚洲精品视频网上网址在线观看| 欧美日韩国产页| 国产成人精品午夜| 国产日韩在线看| 欧美富婆性猛交| 国产精品中文在线| 国内精品小视频| 亚洲欧美日韩高清| 国产午夜精品理论片a级探花| 亚洲精品久久久久久久久久久久久| 亚洲第一精品夜夜躁人人躁| 欧美大片免费观看| 一本色道久久综合亚洲精品小说| 国产精品入口日韩视频大尺度| 97视频在线观看播放| 欧美夜福利tv在线| 亚洲国产精品久久久久| 日韩av在线电影网| 91a在线视频| 91爱视频在线| 日韩高清免费观看| 日本久久久a级免费| 成人国产精品日本在线| 成人亚洲欧美一区二区三区| 国产亚洲精品久久久| 国产精品一区二区av影院萌芽| 亚洲国产精品专区久久| 91av在线免费观看视频| 精品性高朝久久久久久久| 亚洲片在线观看| 亚洲美女性视频| 欧美国产日产韩国视频| 国产suv精品一区二区三区88区| 精品久久久999| 国产精品一二三视频| 久久亚洲国产精品| 亚洲在线视频福利| 日韩欧美亚洲成人| 97超级碰碰碰| 久久久亚洲福利精品午夜| 久久久999国产| 国产精品男人的天堂| 97热在线精品视频在线观看| 狠狠躁夜夜躁人人爽超碰91| 欧美日韩国产中文精品字幕自在自线| 狠狠躁18三区二区一区|