Hdu3172 - Virtual Friends - 并查集
来源:互联网 发布:曲面软件 编辑:程序博客网 时间:2024/05/19 23:04
#include<map> #include<stdio.h> #include<string> using namespace std; #define N 30#define M 100005 int n; int p[M]; int t[M]; map<string,int>Map; int find(int x){ if(p[x]!= x){ int fa=p[x]; p[x]=find(fa); t[x]+=t[fa]; } return p[x]; } void h(int x , int y){ int fx=find(x); int fy=find(y); if(fx!=fy){ p[fx]=fy; t[fy]+=t[fx]; } printf("%d\n",t[fy]); } int main(){ int x,y,m,tot; char str[N]; while(scanf("%d",&m)!=EOF){ while(m--){ scanf("%d",&n); Map.clear(); for(int i=0;i<M;i++){ p[i]=i; t[i]=1; } tot=1; while(n--){ scanf("%s",str); if(Map.find(str)==Map.end()) {Map[str]=tot++;}x=Map[str]; scanf("%s",str); if(Map.find(str)==Map.end()) {Map[str]=tot++;}y=Map[str]; h(x,y); } } } return 0; }
0 0
- HDU3172 Virtual Friends 并查集
- Hdu3172 - Virtual Friends - 并查集
- hdu3172 Virtual Friends--并查集
- hdu3172 Virtual Friends 并查集 map映射
- hdu3172 Virtual Friends 带权并查集
- 带权并查集:HDU3172-Virtual Friends
- HDU3172--Virtual Friends
- hdu3172 Virtual Friends
- hdu3172 Virtual Friends
- HDU3172 Virtual Friends
- hdu3172 Virtual Friends
- HDU3172 Virtual Friends
- hdu3172 Virtual Friends
- HDU3172---Virtual Friends
- hdu3172:Virtual Friends
- HDU3172-Virtual Friends
- HDU3172 UVA11503 Virtual Friends
- HDU3172-Virtual Friends
- MFC显示JPG图片
- c++ 将程序锁定到任务栏
- IE11 开发人员工具
- 勾股定理 (公式转换) 三个数互质(公式)
- 主程序和子程序 分配新指针
- Hdu3172 - Virtual Friends - 并查集
- windows下eclipse+cdt+MinGW搭建C开发环境
- 20140801收盘小结
- Django学习笔记(四)Django使用操作数据库
- 图像的腐蚀原理
- Hdu1075 - What Are You Talking About - 字典树
- Example of Single Pass Clustering Technique
- hdu2680(邻接表+dij)
- POJ2503 - Babelfish - 字典树