//aarifshuvo ``CSEJU #include <bits/stdc++.h> #define ll long long #define SZ(x) ((int)(x).size()) #define scl(x) scanf("%lld", &x) #define scll(x,y) scanf("%lld %lld", &x, &y) #define ALL(x) (x).begin(),(x).end() #define REP(i,n) for(int i=0;i<n;i++) #define REV(i,n) for(int i=n-1;i>=0;i--) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define pri(a) cout<<a<<endl #define prii(a,b) cout<<a<<" "<<b<<endl using namespace std; map<char,char> par; char findr(char ch) { if(par[ch]=='\0') return ch; char x = findr(par[ch]); par[ch]= x; return x; } int main() { ll tc; string s; char ch; bool fl = 0; int mx = 1; scl(tc); while(tc--) { par.clear(); if(fl) printf("\n"); fl=1; cin>>s; ch = s[0]; getchar(); while(getline(cin,s) and s!="") { char ch1 = s[0], ch2 = s[1]; char u = findr(ch1), v = findr(ch2); if(u!=v) par[v] = u; } int cnt = 0; FOR(i,(int)'A',ch) { if(par[i]=='\0') cnt++; } printf("%d\n", cnt); } return 0; }
~Be glad of life because it gives you the chance to love and to work and to play and to look at the stars.~
Thursday, June 1, 2017
UVa 459 Graph Connectivity
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment