1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
#include <iostream> #include <string.h> #include <vector> #include <cstdio> #define SZ 1000001 using namespace std; int par[SZ]; void init() { for(int i=0;i<SZ;i++) par[i]=i; } int find(int a) { if(par[a]==a) return a; else return find(par[a]); } int main() { int t; int n,a,b; int Ycnt,Ncnt; char cmnd,ch; bool f=false; cin>>t; getchar(); while(t--) { cin>>n; init(); getchar(); Ycnt=0; Ncnt=0; while((cmnd=getchar()) && isalpha(cmnd)) { //scanf("%d %d",&a,&ch,&b); getchar(); cin>>a; getchar(); cin>>b; getchar(); int p =find(a); int pp = find(b); if(cmnd=='c') { par[p]=pp; //par[a]=b; } else { if(p==pp) Ycnt++; else Ncnt++; } } if(f) cout<<"\n"; f=1; cout<<Ycnt<<","<<Ncnt<<"\n"; } return 0; } |