Mahmoud and a Dictionary CodeForces
来源:互联网 发布:淘宝促销模板 编辑:程序博客网 时间:2024/06/06 05:36
点击打开链接
将一点拆为两点 a与a'
如果说a与b为朋友
先判断 a和b‘(或a’与b)是不是在同一集合 是的话就错 不是的话就将 a与b a'与b' 合并
如果说a与b为敌人也是一个道理
#include <bits/stdc++.h>using namespace std;map <string,int> mp;int f[200010];int n,m,q;char ch[100010][30];int getf(int p);int main(){ string s; int i,j,t,u,v; int fu1,fv1,fu2,fv2; char ch1[30],ch2[30]; while(scanf("%d%d%d",&n,&m,&q)!=EOF) { mp.clear(); for(i=1;i<=n*2;i++) { f[i]=i; } for(i=1;i<=n;i++) { scanf("%s",ch[i]); s=(string)(ch[i]); mp[s]=i; } while(m--) { scanf("%d%s%s",&t,ch1,ch2); s=(string)ch1; u=mp[s]; s=(string)ch2; v=mp[s]; fu1=getf(u),fv1=getf(v); fu2=getf(u+n),fv2=getf(v+n); if(t==1) { if(fu1!=fv2)//非敌 { printf("YES\n"); f[fv1]=fu1;// f[fv2]=fu2;// } else { printf("NO\n"); } } else { if(fu1==fv1) { printf("NO\n"); } else { printf("YES\n"); f[fv1]=fu2; f[fv2]=fu1; } } } while(q--) { scanf("%s%s",ch1,ch2); s=(string)ch1; u=mp[s]; s=(string)ch2; v=mp[s]; fu1=getf(u),fv1=getf(v); fu2=getf(u+n),fv2=getf(v+n); if(fu1==fv1) { printf("1\n"); } else if(fu1==fv2) { printf("2\n"); } else { printf("3\n"); } } } return 0;}int getf(int p){ if(f[p]==p) return p; else { f[p]=getf(f[p]); return f[p]; }}
阅读全文
0 0
- Mahmoud and a Dictionary CodeForces
- Mahmoud and a Dictionary CodeForces
- Mahmoud and a Dictionary CodeForces
- Mahmoud and a Dictionary CodeForces
- 【codeforces 766D】Mahmoud and a Dictionary
- codeforces 766D Mahmoud and a Dictionary
- Codeforces 766D Mahmoud and a Dictionary
- Codeforces 766D-Mahmoud and a Dictionary
- codeforces 766D. Mahmoud and a Dictionary
- Codeforces Round #396 (Div. 2)Mahmoud and a Dictionary
- D. Mahmoud and a Dictionary
- 【题解】codeforces766D Mahmoud and a Dictionary
- Mahmoud and a Dictionary codeforces396 div2 D
- Mahmoud and a Message CodeForces
- Mahmoud and a Triangle (CodeForces
- Codeforces Round #396 (Div. 2)-D. Mahmoud and a Dictionary(关系并查集)
- Codeforces Round #396 (Div. 2)-D. Mahmoud and a Dictionary(并查集)
- Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary(并查集)
- ofbiz实战——实验项目管理界面以及代码
- 搜索引擎
- TCP/IP协议入门(一)--阮一峰
- Linux下Python递归文件目录
- 获取虚拟机的IP地址
- Mahmoud and a Dictionary CodeForces
- 云计算与devops
- 客户端启动redis报错
- 安全
- 互联网协议入门(二)
- 错过等半年 | 年薪30万都要学的Linux云计算课程,即将满80人班
- Python风靡全宇宙,首要原因是它?
- 麦当劳改名“金拱门”后,整个IT圈彻底沦陷了......
- 【大咖讲堂178期】 | Zabbix与Python不得不说的基情