POJ 1611(并查集)
2012-09-30 21:11
197 查看
唯一的WA
是把0的父亲当成祖先
father[x]和getfather(x)差别巨大啊
是把0的父亲当成祖先
father[x]和getfather(x)差别巨大啊
Program p1611; const maxn=30010; maxm=500; var n,m,i,j,k,p1,p2,ans,f0:longint; father:array[0..maxn] of longint; function getfather(x:longint):longint; begin if father[x]=x then exit(x); father[x]:=getfather(father[x]); exit(father[x]); end; procedure union(x,y:longint); begin if getfather(x)<>getfather(y) then father[father[x]]:=father[father[y]]; end; begin read(n,m); while (n+m>0) do begin for i:=0 to n-1 do father[i]:=i; for i:=1 to m do begin read(k); if k>0 then read(p1); if k>1 then for j:=2 to k do begin read(p2); union(p1,p2); end; end; ans:=1; f0:=getfather(0); for i:=1 to n-1 do if getfather(i)=f0 then inc(ans); writeln(ans); read(n,m); end; end.
相关文章推荐
- poj 1611 (并查集)
- 并查集(poj1611、2524、2492、1182)
- POJ 1611 The Suspects (并查集)
- POJ 1611 The Suspects(并查集,简单)
- POJ 1611 The Suspects 并查集
- POJ 1611 The Suspects【并查集入门】
- POJ 1611 The Suspects (并查集)
- POJ 1611 ACM数据结构The Suspects (并查集)
- POJ---1611 The Suspects[并查集]
- POJ 题目1611 The Suspects(简单并查集,带权值)
- POJ1611 - The Suspects (并查集的应用)
- 3.27 三二 B POJ 1611 SARS 并查集
- POJ 1611 The Suspects (并查集)
- poj 1611 The Suspects(启发式式合并,并查集)
- POJ 1611 并查集详解+基础应用
- poj 1611 The Suspects(并查集)
- poj 1611 The Suspects 并查集
- Poj1611 The Suspects 并查集基础题
- POJ1611 并查集 基础 比 2524 复杂一些
- POJ 1611 The Suspects 并查集