Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author : unlucky_13
- Problem_link :
- Category : TOO Easy
- Algorithm_Used : Disjoint-Set
- */
- #include<cstdio>
- #include<sstream>
- #include<cstdlib>
- #include<cctype>
- #include<cmath>
- #include<algorithm>
- #include<set>
- #include<queue>
- #include<stack>
- #include<list>
- #include<iostream>
- #include<fstream>
- #include<numeric>
- #include<string>
- #include<vector>
- #include<cstring>
- #include<map>
- #include<iterator>
- #define LL long long int
- //const long long int inf = 2147483647 ;
- //const int minx=;
- const int maxn=200;
- using namespace std;
- int par[maxn][2] ;
- int find(int u,int i){
- if(par[u][i]==u) return u ;
- return par[u][i]= find(par[u][i],i) ;
- }
- int main() {
- freopen("C:\\Users\\Mazhar\\Desktop\\in.txt", "r", stdin);
- int tc ,n;
- char to,from;
- scanf("%d",&tc) ;
- bool blank = false ;
- while(tc--){
- if(blank) printf("\n") ;
- else blank = true ;
- for(int i=0;i<30;i++){
- par[i][0] = par[i][1] = i ;
- }
- scanf("%d\n",&n) ;
- for(int i=0;i<n;i++){
- scanf("%c %c\n",&to,&from) ;
- int U = find(to-'A',0) ;
- int V = find(from-'A',0) ;
- if(U!=V) par[U][0]=V ;
- }
- scanf("%d\n",&n) ;
- for(int i=0;i<n;i++){
- scanf("%c %c\n",&to,&from) ;
- int U = find(to-'A',1) ;
- int V = find(from-'A',1) ;
- if(U!=V) par[U][1]=V ;
- }
- bool res=true ; ;
- for(int i=0;i<30;i++){
- if(find(i,0)!=find(i,1)){
- res = false ;
- break ;
- }
- }
- if(res) printf("YES") ;
- else printf("NO") ;
- printf("\n") ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment