标签:expr return pos 编号 sample 3.1 并查集 output whether
Ubiquitous Religions
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 34826 | Accepted: 16788 |
Description
Input
Output
Sample Input
10 9 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 10 4 2 3 4 5 4 8 5 8 0 0
Sample Output
Case 1: 1 Case 2: 7
Hint
Source
#include <iostream> using namespace std; int parent[50005]; int findSource(int s) { return parent[s]==s?s:findSource(parent[s]); } int main() { ios::sync_with_stdio(false); int n,m,CASE=0; while(cin>>n>>m) { CASE++; if(n==0&&m==0) { return 0; } int s1,s2; for(int i=0;i<50005;++i) { parent[i]=i; } while(m--) { cin>>s1>>s2; if(findSource(s1)!=findSource(s2)) { parent[findSource(s2)]=findSource(s1); n--; } } cout<<"Case "<<CASE<<": "<<n<<endl; } return 0; }
标签:expr return pos 编号 sample 3.1 并查集 output whether
原文地址:http://www.cnblogs.com/Algorithm-X/p/7072170.html