poj 1611 并查集
来源:互联网 发布:数据库攻击手段sql注入 编辑:程序博客网 时间:2024/05/18 00:13
我只会做水题
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int parent[30003];
void set(int n)
{
for(int i=0;i<n;i++)
{
parent[i]=-1;
}
}
int find(int x)
{
int s;
for(s=x;parent[s]>=0;s=parent[s])
;
while(x!=s)
{
int tmp=parent[x];
parent[x]=s;
x=tmp;
}
return s;
}
void u(int R1,int R2)
{
int r1=find(R1);
int r2=find(R2);
int tmp=parent[r1]+parent[r2];
if(parent[r1]>parent[r2])
{
parent[r1]=r2;
parent[r2]=tmp;
}
else
{
parent[r2]=r1;
parent[r1]=tmp;
}
}
int a[30003];
int main()
{
int m,n,i,j,k,l,s;
while(cin>>n>>m)
{
if(m==0&&n==0)
break;
set(n);
while(m--)
{
cin>>s;
for(i=0;i<s;i++)
{
cin>>a[i];
if(i>0&&find(a[i-1])!=find(a[i]))
u(a[i],a[i-1]);
}
}
int tmp=find(0);
cout<<-1*parent[tmp]<<endl;
// cout<<find(0);
}
return 0;
}
- 并查集 POJ 1611
- 【并查集】POJ-1611
- poj 1611(并查集)
- poj 1611 并查集
- poj 1611 并查集
- 【POJ 1611 并查集】
- poj 1611 并查集
- poj 1611(并查集)
- poj-1611 并查集
- POJ 1611 并查集
- poj 1611 并查集
- POJ 1611 (并查集)
- POJ 1611 <并查集>
- poj 1611 并查集
- 并查集 POJ 1611
- POJ 1611 (并查集)
- Poj 并查集
- poj并查集
- SQL Server DBA调优日记(一)——大数据量查询记录数优化及原理探讨
- 【正则表达式判断】Regular Expression Matching
- EasyUI - Datebox和Numberbox的使用
- BZOJ 1192 [HNOI2006] 鬼谷子的钱袋 题解
- 20140406 TCPL 第十二章 派生类
- poj 1611 并查集
- START WITH...CONNECT BY PRIOR用法
- Asp.net—DropDownList与listbox的联动
- outlook自动弹出
- STL count_if应用
- 开发心得之一
- IIC通信底层
- shell获取某个时间段的nginx日志内容
- 浅析C++中的this指针