hihocoder 1066 无间道(基础并查集)
来源:互联网 发布:淘宝助理上传宝贝显示0 编辑:程序博客网 时间:2024/05/22 09:56
基础并查集题目,拿来当做并查集上手不错
#include<cstdio>#include<iostream>#include<string>#include<map>using namespace std;int parent[100002];void init(){ for(int i=1;i<=100001;i++) { parent[i]=i; }}int find(int x){ if(x==parent[x]) return x; else { return parent[x]=find(parent[x]); }}void join(int x,int y){ int fx=find(x), fy=find(y); if(fx == fy) return; parent[fx]=fy;}bool query(int x,int y){ return find(x)==find(y);}int main(){ int op,op_i; init(); string n1,n2; map<string,int>M; int id=0; scanf("%d",&op); while(op--) { scanf("%d",&op_i); cin>>n1; if(!M.count(n1)) M[n1]=id++; cin>>n2; if(!M.count(n2)) M[n2]=id++; if(op_i==0) { join(M[n1],M[n2]); } else if(op_i==1) { if(query(M[n1],M[n2])) printf("yes\n"); else printf("no\n"); } } return 0;}
0 0
- hihocoder 1066 无间道(基础并查集)
- hihocoder:无间道之并查集
- hihocoder 无间道之并查集
- hihoCoder 无间道之并查集
- [ACM] hihocoder 1066 无间道之并查集
- [HiHoCoder]#1066 : 无间道之并查集
- hihoCoder 1066 : 无间道之并查集
- hihocoder#1066 : 无间道之并查集
- hihocoder#1066 : 无间道之并查集
- hihoCoder - 1066 - 无间道之并查集
- hihoCoder 1066 无间道之并查集
- hihocoder #1066 : 无间道之并查集
- hihoCoder 1066 无间道之并查集
- [HihoCoder]#1066 : 无间道之并查集
- hihoCoder 1066 : 无间道之并查集
- hihoCoder - 1066 - 无间道之并查集 (并查集 + map)
- 并查集-----hihocoder无间道之并查集
- hihoCoder 1066 : 无间道之并查集(字符串Hash函数)
- 深度学习训练技巧
- TextView不用获取焦点也能实现跑马灯
- DRX不连续接收(2)-寻呼Paging
- vs2010 标识可以右键转到定义,但是编译时提示未声明的标识符
- JAVA基础教程(3)--JVM是什么
- hihocoder 1066 无间道(基础并查集)
- EasyUI 开始时间小于结束时间和tooptip
- MAC上没有.bash_profile该怎么办?
- 二进制中1的个数
- Javascript Promise
- Python网络编程学习笔记一:socket模块
- python metaclass
- linux命令
- 2017年最佳编程语言学习