445B - DZY Loves Chemistry
来源:互联网 发布:看网球软件 编辑:程序博客网 时间:2024/05/24 04:02
这是一道并查集的题目,而且是很简单的并查集的题目。只要具备初等并查集的知识这道题都不是难事。所以这里不讲。
#include<iostream>using namespace std;#include<stdio.h>int pre[55];int find(int x){ int r=x; while(pre[r]!=r)r=pre[r]; int i=x; int j; while(i!=r) { j=pre[i]; pre[i]=r; i=j; } return r;}int main(){ int i,j,m,n; int sum; int k1,k2; __int64 num; while(cin>>n>>m) { sum=0; num=1; for(i=0;i<55;i++)pre[i]=i; for(i=0;i<m;i++) { scanf("%d%d",&k1,&k2); int p1=find(k1); int p2=find(k2); if(p1!=p2) { sum++; pre[p1]=p2; } } for(i=1;i<=sum;i++) num*=2; cout<<num<<endl; }}
0 0
- 445B - DZY Loves Chemistry
- Codeforces 445B. DZY Loves Chemistry
- Codeforces 445B DZY Loves Chemistry
- CodeFroces 445B DZY Loves Chemistry
- E--DZY Loves Chemistry(CF-445B
- CODEFORCES 445B DZY Loves Chemistry
- Codeforces 445B DZY Loves Chemistry
- CodeForces 445B DZY Loves Chemistry
- codeforces-B. DZY Loves Chemistry
- CodeForces 445B. DZY Loves Chemistry(并查集)
- CF 445B(DZY Loves Chemistry-求连通块)
- Codeforces 445B DZY Loves Chemistry(并查集)
- CodeForces 445B DZY Loves Chemistry(并查集)
- CodeForces 445B DZY Loves Chemistry (并查集)
- CodeForces 445B - DZY Loves Chemistry(并查集)
- 【codeforces 445B - DZY Loves Chemistry 】 + 并查集
- CodeForces 445B DZY Loves Chemistry (并查集)
- codeforces 445 B. DZY Loves Chemistry (并查集)
- Hadoop2.0完全分布式安装(无HA 联邦)
- 关于做Android+J2ee系统集成开发的一点心得
- 【九度OJ】1035【Floyd算法】
- 2014年8月17日晚
- 百度语音识别的文档链接
- 445B - DZY Loves Chemistry
- Win32_Sec day
- 程序员生存定律-六个程序员的故事(1)
- atitit. groupby linq的实现(1)-----linq框架选型 java .net php
- TCP/IP 学习答疑
- 堆排序
- socket调用流程分析
- 泛型for
- OC总结二JSON解析