uvalive 3644 X-Plosives
来源:互联网 发布:手机打网络电话软件 编辑:程序博客网 时间:2024/06/07 02:30
思路:简单的并查集应用,两个点有相同的祖先是组成环,会引起爆炸,不能放,num++。
#include <iostream>#include <cstring>#include <stdio.h>using namespace std;int f[100008];int find(int x){ return x==f[x]?x:f[x]=find(f[x]);}int init(){ for(int i=0;i<100008;i++) f[i]=i; return 1;}int main(){ //freopen("in.txt","r",stdin); int x,y,num=0; init(); while(scanf("%d",&x)!=EOF) { if(x==-1) { printf("%d\n",num); num=0; init(); continue; } scanf("%d",&y); int xx=find(x); int yy=find(y); if(xx==yy) num++; else f[xx]=yy; find(x); }}
0 0
- UVALive 3644 X-Plosives
- UVALive 3644 X-Plosives
- UVALive 3644 X-Plosives
- UVALive - 3644 X-Plosives
- UVALive 3644 X-Plosives
- UVALive - 3644 X-Plosives
- uvalive 3644 X-Plosives
- UVALive 3644 X-Plosives 并查集
- UVALive - 3644 X-Plosives 并查集
- UVALive - 3644 X-Plosives 并查集
- 【暑假】[实用数据结构]UVAlive 3644 X-Plosives
- UVALive - 3644X-Plosives(并查集)
- UVALive - 3644 - X-Plosives (并查集!!)
- UVALive(LA) 3644 X-Plosives (并查集)
- uvalive 3644 X-Plosives(并查集)
- UVALive 3644 X-Plosives(简单并查集)
- UVALive 3644 X-Plosives (并查集)
- X-Plosives +uvalive+并查集+水题
- 《大型网络技术架构》笔记 2
- 第八周第二天
- C++Primer第五版 7.1.4节练习
- 破解限制单机上网方法
- 10810 - Ultra-QuickSort(求逆序数)
- uvalive 3644 X-Plosives
- Android之Fragment(碎片)
- UE4 Material - How To Use Fresnel in your Materials
- /proc/modules, /proc/devices, /dev
- 1215 七夕节
- android之音频的播放和录制(MediaPlayer,SoundPool,MediaRecorder)
- ios数据初级持久化 存储复杂对象
- Java初体验(二)
- 全球顶级域名及国家域名列表