UVALive 3644 X-Plosives
来源:互联网 发布:fangcms源码下载 编辑:程序博客网 时间:2024/06/03 18:06
赤裸裸的并查集。。。。
代码:
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<map>#include<queue>#include<stack>#include<cmath>#include<vector>#define inf 0x3f3f3f3f#define Inf 0x3FFFFFFFFFFFFFFFLL#define eps 1e-9#define pi acos(-1.0)using namespace std;const int maxn=100000+10;int parents[maxn];int Find(int x){ if(x!=parents[x]) { parents[x]=Find(parents[x]); } return parents[x];}bool Uion(int x,int y){ int a=Find(x); int b=Find(y); if(a!=b) { parents[b]=a; return true; } return false;}int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int a,b,sum=0; while(cin>>a) { sum=0; cin>>b; for(int i=0;i<maxn;++i) parents[i]=i; Uion(a,b); while(cin>>a) { if(a==-1) break; cin>>b; if(!Uion(a,b)) sum++; } cout<<sum<<endl; } return 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+并查集+水题
- input标签、radio标签、checkbox标签、select标签
- Unity3d读写文件操作
- android中为TextView动态改变字体颜色,如点击时更改
- JAVA读取XML文件
- 有关HTML5学习资料
- UVALive 3644 X-Plosives
- DSS General Event-Based Derived Flow
- servlet规范版本的差异以及Tomcat各版本的支持情况
- Android资源目录assets及raw
- JS实现文本框获得焦点,文本框里提示信息自动消失
- 开发人员眼中最好的代码编辑器
- 2013蓝桥杯 错误票据 解题方法及代码
- 百度推广资质收取要求
- html札记一