POJ 1611The Suspects(简单并查集)
来源:互联网 发布:财税软件 编辑:程序博客网 时间:2024/05/22 13:37
题目地址:http://poj.org/problem?id=1611
网络流先慢慢看着。。先开始并查集专题吧。。
这题很简单,就是一道并查集模板题。不多说。。
#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <algorithm>using namespace std;int bin[40000], n;int find1(int x){ return bin[x]==x?x:bin[x]=find1(bin[x]);}void merge1(int f1, int f2){ f1=find1(f1); f2=find1(f2); if(f1!=f2) { if(f1<f2) { bin[f2]=f1; } else bin[f1]=f2; }}int main(){ int m, k, i, j, ans, x, y; while(scanf("%d%d",&n,&m)!=EOF&&(n||m)) { for(i=0;i<n;i++) { bin[i]=i; } while(m--) { scanf("%d",&k); scanf("%d",&x); for(i=1;i<k;i++) { scanf("%d",&y); merge1(x,y); } } ans=0; for(i=0;i<n;i++) { if(find1(i)==0) { ans++; } } printf("%d\n",ans); } return 0;}
0 0
- POJ 1611The Suspects(简单并查集)
- POJ-1611-The Suspects (简单并查集!)
- POJ - 1611 The Suspects(简单并查集)
- POJ 1611 The Suspects(并查集,简单)
- poj 1611 The Suspects(简单并查集)
- POJ 1611 The Suspects(简单并查集)
- zoj 1789||poj 1611 The Suspects(并查集,简单)
- poj 1611 The Suspects(简单并查集)
- POJ 1611 The Suspects【简单并查集】
- POJ 1611 The Suspects [简单并查集应用]
- POJ 1611 The Suspects 并查集简单题
- POJ 1611 The Suspects(并查集)
- poj 1611 The Suspects 并查集
- POJ 1611 The Suspects 并查集
- poj 1611 The Suspects(并查集)
- POJ 1611 The Suspects 并查集
- POJ--1611--The Suspects【并查集】
- poj 1611-The Suspects:并查集
- cocos2dx UI自适应屏幕
- 机器学习经典书籍
- 赵老师的走迷宫
- linux shell命令 链接FTP下载文件 备注
- C++学习之智能指针
- POJ 1611The Suspects(简单并查集)
- JSP分页代码
- mysql 宕机 innodb_force_recovery,innodb_fast_shutdown对数据的影响
- Java_SAX解析XML
- Swift 概述及Swift运算符和表达式
- 4-NLP有用资料整理
- Android 中Parcelable的作用
- create a cocos2d-x-3.0 project in Xcode
- 让powershell在不显示提示信息的情况下通过Internet上下载的ps脚本