Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define i64 long long int
- #define pi acos(-1.00)
- struct side
- {
- char a;
- char b;
- }
- get;
- map<char,char>parent;
- void Make(char ch)
- {
- parent[ch]=ch;
- }
- char Find(char ch)
- {
- if(parent[ch]==ch)
- {
- return ch;
- }
- return parent[ch]=Find(parent[ch]);
- }
- void setunion(char a,char b)
- {
- char A = Find(a);
- char B = Find(b);
- if(A==B)
- {
- return ;
- }
- else
- {
- parent[A]=B;
- cout<<"parent A -> " <<parent[A]<<" Parent B -> "<<parent[B]<<endl;
- return;
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- int i,t,j,k;
- // cin>>t;
- char ch;
- char str;
- char s[3];
- char space1;
- char maxN;
- vector<side>vec;
- for(int i = 1; i<=t; i++)
- {
- cin>>str;
- cout<<"hi "<<endl;
- int cnt[30];
- memset(cnt,0,sizeof(cnt));
- maxN = str;
- int p = maxN-0;
- char c;
- for(int j= 65; j<=p; j++)
- {
- c = j;
- Make(c);
- /// cout<<parent[c]<<endl;
- }
- cout<<"hello"<<endl;
- char ch1,ch2;
- while( gets(s) )
- {
- cout<<"s -> "<<s<<endl;
- ch1 = s[0];
- if(ch==' ')
- {
- return 0;
- }
- ch2 = s[1];
- get.a =ch1;
- get.b = ch2;
- vec.push_back(get);
- cout<<"Pushed "<<endl;
- }
- for(int j =0 ; j<vec.size(); j++)
- {
- char from = vec[i].a;
- char to = vec[i].b;
- setunion(from,to);
- }
- map<char,char>::iterator it;
- for(it = parent.begin(); it!= parent.end(); ++it)
- {
- char C = it->second;
- char C1 = it->first;
- cout<<"C -> "<<C<<" C1-> "<<C1<<endl;
- }
- int mx = INT_MIN;
- for(int i =0; i<30; i++)
- {
- cout<<"cnt["<<i<<"] -> "<<cnt[i]<<endl;
- mx = max(mx,cnt[i]);
- }
- cout<<"ans -> "<<mx<<endl;
- parent.clear();
- vec.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement