poj1611解题报告
2012-10-16 11:44
281 查看
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> using namespace std ; const int MAXN = 30005 ; int father[MAXN] ; int find( int x ) { if( father[x] != x ) father[x] = find( father[x] ) ; return father[x] ; } void Union( int a , int b ) { int f1 = find( a ) ; int f2 = find( b ) ; if( f1 != f2 ) father[f2] = f1 ; } int main() { int n , m , num , student[MAXN] , Count ; while( scanf( "%d%d" , & n , & m ) && n ) { Count = 1 ; for( int i = 0 ; i <= n ; i ++ ) father[i] = i ; while( m -- ) { scanf( "%d" , & num ) ; for( int i = 0 ; i < num ; i ++ ) scanf( "%d" , & student[i] ) ; for( int i = 1 ; i < num ; i ++ ) Union( student[0] , student[i] ) ; } int temp = find( 0 ) ; for( int i = 1 ; i < n ; i ++ ){ if( find( i ) == temp ) Count ++ ; } printf( "%d\n" , Count ) ; } return 0 ; }
这道题也是并查集的题
我就直接粘代码了
相关文章推荐
- POJ 1611 解题报告
- 【解题报告】 POJ 1611 The Suspects 并查集基础 (一点自己的感悟)
- 【原创】poj ----- 1611 The Suspects 解题报告
- poj 1611 The Suspects 解题报告
- 【原】 POJ 1611 The Suspects 并查集 解题报告
- POJ 1611 The Suspects 解题报告
- PKU POJ 1611解题报告(并查集)
- POJ - 1611 The Suspects解题报告
- 并查积初步之poj1611解题报告
- POJ 2375 解题报告
- POJ 1979 Red and Black 解题报告
- poj 2376解题报告(详细) 带几组测试数据
- Poj 1011 解题报告
- Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)
- poj解题报告——3414
- poj解题报告——3267
- poj1013解题报告
- POJ 3239解题报告
- POJ 2993 Emag eht htiw Em Pleh解题报告
- 一往直前!贪心法 区间 poj 2376解题报告