/***
Md. Namzul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
int pr[100001] ;
int suc,unsuc ;
int find_r(int r)
{
if(pr[r]==r)
return r ;
return (pr[r]=find_r(pr[r])) ;
}
void disjoint_set(int u, int v)
{
int a = find_r(u) ;
int b = find_r(v) ;
if(a==b)
return ;
else
{
pr[a]=b ;
}
}
int main()
{
int test ,n,u,v,i ;
sc("%d",&test) ;
char ch ;
char str[10001] ;
bool l =false ;
while(test--)
{
if(l)
pf("\n") ;
l =true ;
suc =0 ;
unsuc =0 ;
sc("%d\n",&n) ;
//getchar() ;
for(i=1 ; i<=n ; i++)
pr[i] =i ;
while(gets(str) && strlen(str))
{
sscanf(str,"%c %d %d",&ch,&u,&v) ;
if(ch=='c')
{
disjoint_set(u,v) ;
}
else
{
int a = find_r(u) ;
int b = find_r(v) ;
if(a==b)
suc++ ;
else
unsuc++ ;
}
}
pf("%d,%d\n",suc,unsuc) ;
}
return 0;
}
Md. Namzul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
int pr[100001] ;
int suc,unsuc ;
int find_r(int r)
{
if(pr[r]==r)
return r ;
return (pr[r]=find_r(pr[r])) ;
}
void disjoint_set(int u, int v)
{
int a = find_r(u) ;
int b = find_r(v) ;
if(a==b)
return ;
else
{
pr[a]=b ;
}
}
int main()
{
int test ,n,u,v,i ;
sc("%d",&test) ;
char ch ;
char str[10001] ;
bool l =false ;
while(test--)
{
if(l)
pf("\n") ;
l =true ;
suc =0 ;
unsuc =0 ;
sc("%d\n",&n) ;
//getchar() ;
for(i=1 ; i<=n ; i++)
pr[i] =i ;
while(gets(str) && strlen(str))
{
sscanf(str,"%c %d %d",&ch,&u,&v) ;
if(ch=='c')
{
disjoint_set(u,v) ;
}
else
{
int a = find_r(u) ;
int b = find_r(v) ;
if(a==b)
suc++ ;
else
unsuc++ ;
}
}
pf("%d,%d\n",suc,unsuc) ;
}
return 0;
}
No comments:
Post a Comment