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

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

Mahmoud and a Dictionary codeforces396 div2 D

2019-11-10 17:59:07
字體:
來源:轉載
供稿:網友

D. Mahmoud and a Dictionary time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard 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,不確定輸出3;

帶權并查集:不懂的可以看下這道:http://blog.csdn.net/littlewhite520/article/details/53521037 只有兩個值 1和 2 兩種狀態所以%2就行,保持在 0 1,要輸出不確定的為3,記住,不在一棵樹里面的就是不確定的。

#include <bits/stdc++.h>using namespace std;const int maxn=1e5+7;int f[maxn];int relation[maxn];map <string,int > mp;int find(int x){ if(x!=f[x]) { int t=f[x]; f[x]=find(f[x]); relation[x]=(relation[x]+relation[t])%2; } return f[x];}int main(){ int n,m,q; while(cin>>n>>m>>q) { string s; for(int i=0;i<n;i++) { cin>>s; mp[s]=i; } for(int i=0;i<n;i++) { f[i]=i; relation[i]=0; } string s1; int v; while(m--) { cin>>v>>s>>s1; v--; int f1=mp[s]; int f2=mp[s1]; int t1=find(f1); int t2=find(f2); if(t1!=t2) { printf("YES/n"); f[t1]=t2; relation[t1]=(v-relation[f1]+relation[f2]); } else { int p=(relation[f1]-relation[f2]+2)%2; if(p==v) puts("YES"); else puts("NO"); } } while(q--) { cin>>s>>s1; int f1=mp[s]; int f2=mp[s1]; int t1=find(f1); int t2=find(f2); if(t1!=t2) { puts("3"); } else { int p=(relation[f1]-relation[f2]+2)%2; printf("%d/n",p+1 ); } } }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
亚州av一区二区| 久久精品亚洲热| 亚洲国产女人aaa毛片在线| 欧美电影免费观看网站| 日韩av不卡在线| 久久国产精品久久精品| 国外成人性视频| 欧美精品第一页在线播放| 最近2019年中文视频免费在线观看| 精品久久久久久久久国产字幕| 欧美午夜激情在线| 岛国精品视频在线播放| 欧美黑人极品猛少妇色xxxxx| 国产精品第10页| 日本久久久久久久久久久| 精品中文字幕在线2019| 奇门遁甲1982国语版免费观看高清| 国产精品va在线| 欧美国产在线视频| 国产福利成人在线| 韩国三级日本三级少妇99| 中文字幕国产亚洲2019| 欧美日韩国产精品一区二区三区四区| 亚洲激情国产精品| 成人黄色片网站| 欧美国产日韩一区二区| 亚洲第一页中文字幕| 热久久99这里有精品| 黑人狂躁日本妞一区二区三区| 久久精品视频播放| 国产成人精品日本亚洲| 麻豆一区二区在线观看| 亚洲精品中文字幕女同| 亚洲一区制服诱惑| 欧美高清激情视频| 九九久久综合网站| 国产999精品久久久| 精品国产欧美成人夜夜嗨| 久久久女女女女999久久| 亚洲成人在线网| 91高清视频免费观看| 国产精品一区久久| 色噜噜国产精品视频一区二区| 91免费综合在线| 国产一区二区三区毛片| www.亚洲一二| 国产视频久久网| 国产亚洲欧洲高清一区| 久久高清视频免费| 亚洲国产另类 国产精品国产免费| 高清一区二区三区日本久| 国产在线观看91精品一区| 亚洲最新中文字幕| 91精品国产高清自在线看超| 国产午夜精品全部视频播放| 91精品国产99久久久久久| 国产精品99蜜臀久久不卡二区| 日本高清不卡在线| 久久男人资源视频| 欧美丝袜美女中出在线| 91精品久久久久久久| 国产视频在线观看一区二区| www国产亚洲精品久久网站| 成人免费看片视频| 国产成人+综合亚洲+天堂| 亚洲图片在区色| 欧美一级黑人aaaaaaa做受| 国产亚洲成精品久久| 久热精品视频在线观看| 亚洲人高潮女人毛茸茸| 日韩精品中文字幕视频在线| 欧美成人精品三级在线观看| 欧美激情视频在线| 久久精品青青大伊人av| 欧美激情在线视频二区| 性欧美xxxx| 午夜美女久久久久爽久久| 91在线观看欧美日韩| 国产午夜精品视频免费不卡69堂| 俺去了亚洲欧美日韩| 久久久精品美女| 亚洲美女性视频| 成人日韩av在线| 精品视频在线播放色网色视频| 精品毛片网大全| 国产日韩欧美在线播放| 91免费高清视频| 欧美午夜影院在线视频| 欧美中文字幕精品| 国产亚洲精品久久久久久| 国产精品成人aaaaa网站| 国产亚洲精品久久久久久牛牛| 日韩午夜在线视频| 亚洲在线视频福利| 亚洲欧美中文在线视频| 欧美怡春院一区二区三区| 亚洲一区二区三区乱码aⅴ| 国产视频久久网| 美女精品久久久| 亚洲国产精品免费| 91久久久在线| 欧美资源在线观看| 国产精品入口免费视频一| 日本精品久久久久久久| 国产亚洲精品久久久优势| 91精品国产91久久久久福利| 91久热免费在线视频| 亚洲欧洲午夜一线一品| 97视频免费观看| 国产精品亚洲欧美导航| 91极品视频在线| 久久久视频在线| 日韩欧美大尺度| 亚洲视频999| 欧美综合第一页| 2020欧美日韩在线视频| 欧美日韩激情美女| 中文字幕自拍vr一区二区三区| 日韩国产激情在线| 黑人巨大精品欧美一区二区三区| 精品国产欧美一区二区三区成人| 中文综合在线观看| 中文国产成人精品久久一| 亚洲欧美国产一本综合首页| 亚洲**2019国产| 亚洲午夜未满十八勿入免费观看全集| 中文字幕日韩精品在线观看| 亚洲在线免费看| 久久久久亚洲精品国产| 国产精品视频资源| 国产成人精品网站| 亚洲天堂免费视频| 精品国产电影一区| 国产精品丝袜视频| 成人免费高清完整版在线观看| 色噜噜国产精品视频一区二区| 欧美性jizz18性欧美| 亚洲a中文字幕| 欧美亚洲日本黄色| 欧美福利在线观看| www国产91| 亚洲人成电影在线| 最新中文字幕亚洲| 色噜噜狠狠狠综合曰曰曰| 91精品国产高清自在线看超| 国产一区二区黄| 91系列在线观看| 中文字幕亚洲色图| 97av在线播放| 日韩欧美在线一区| 久久久精品视频在线观看| 亚洲男女性事视频| 亚洲日本aⅴ片在线观看香蕉| 日韩av一区在线| 日韩免费精品视频| 欧美激情国内偷拍| 欧美日韩国产色视频| 91在线看www| 人人做人人澡人人爽欧美| 欧美亚洲免费电影| 全亚洲最色的网站在线观看| 久久69精品久久久久久久电影好| 九九精品在线观看| 亚洲天堂视频在线观看|