标签:des style io color ar os sp for on
Problem description
A secret service developed a new kind of explosive that attain its volatile property only when a speci c
association of products occurs. Each product is a mix of two different simple compounds, to which weCompute the number of refusals given a sequence of binding pairs.
Input
Output
For each test case, the output must follow the description below.A single line with the number of refusals.
Sample Input
1 2-1
Sample Output
3
# include <iostream> # include <cstdio> using namespace std; # define Max 100000+5 int par[Max]; int found(int x) { return par[x]!=x ? par[x]=found(par[x]) : x; } int main() { int x,y; while(cin>>x) { int sum=0; int i; for(i=0;i<Max;i++) par[i]=i; while(x!=-1) { cin>>y; x=found(x); y=found(y); if(x==y) sum++; else par[x]=y; cin>>x; } cout<<sum<<endl; } return 0;}
标签:des style io color ar os sp for on
原文地址:http://blog.csdn.net/rechard_chen/article/details/41216337