UVALive X-Plosives(并查集+略坑的输入)
来源:互联网 发布:php断点续传原理 编辑:程序博客网 时间:2024/06/18 08:20
1.此题的题意非常简单,但是题目可能较难读懂
2.输入输出是坑,输入-1后再输入eof文件才结束,且
3.此题的代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
using namespace std;
int fat[100100];
int Find(int a)
{
while(fat[a]!=a)
a = fat[a];
return a;
}
void join(int a,int b)
{
int fx=Find(a),fy=Find(b);
if(fx!=fy)
fat[fx]=fy;
}
void init()
{
for(int i=1;i<=100050;i++)
fat[i]=i;
}
int main()
{
int num1,num2,ans=0;
while(~scanf("%d%d",&num1,&num2))
{
ans=0;
init();
join(num1,num2);
while(scanf("%d",&num1),num1!=-1)
{
scanf("%d",&num2);
if(Find(num1)!=Find(num2))
{
join(num1,num2);
}
else
{
//cout<<num1<<num2<<endl;
ans++;
}
}
printf("%d\n",ans);
}
return 0;
}
- UVALive X-Plosives(并查集+略坑的输入)
- X-Plosives +uvalive+并查集+水题
- UVALive 3644 X-Plosives 并查集
- UVALive - 3644 X-Plosives 并查集
- UVALive - 3644 X-Plosives 并查集
- UVALive(LA) 3644 X-Plosives (并查集)
- UVALive - 3644X-Plosives(并查集)
- UVALive - 3644 - X-Plosives (并查集!!)
- uvalive 3644 X-Plosives(并查集)
- UVALive 3644 X-Plosives (并查集)
- UVALive 3644 X-Plosives(简单并查集)
- 指南 第三章 例题5 UVALive 3644 X-Plosives(并查集)
- uva1160 - X-Plosives (并查集)
- BNU X-Plosives(并查集) @
- uva 1160 - X-Plosives(并查集)
- uva 1160 - X-Plosives(并查集)
- ACM LA3644: X-Plosives(并查集)
- UVA 1160 X-Plosives(并查集)
- fcntl设置文件描述符
- FPGA设计-时序约束(上篇,理论篇)
- 修复IE6,7--DIV浮动情况下margin-bottom失效
- 二维图形变换
- JavaScript初探二
- UVALive X-Plosives(并查集+略坑的输入)
- VTK根据几个点插值成样条曲线,然后以样条曲线为中心线,生成圆柱体管道
- FPGA开发流程1(详述每一环节的物理含义和实现目标)
- 【JZOJ 3839】Baby Step
- 148. Sort List**
- Delphi7下SuperObject的JSON使用方法
- HDU 4794 Arnold (斐波那契数模 n 的应用)
- leetcode oj java 337. House Robber III
- UGUI - Text控件