OJ
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
#define PF(x) (scanf("%d",&x))
#define PT(x,y) (scanf("%d%d",&x,&y))
#define PR(x) (printf("%d\n",x))
#define PRT(x,y)(printf("%d %d\n",x,y))
#define PB(x)(scanf("%I64d",&x))
#define PRB(x)(printf("%I64d\n",(x)))
typedef __int64 LL;
#define N 100005
#define M 105
#define Mod 1000
#define Inf 0x7fffffff
int ar[N];
int f[N];
int n;
int find(int r)
{
if(ar[r] == r) return r;
int t = find(ar[r]);
ar[r] = t;
return t;
}
void uns(int a,int b)
{
ar[a] = b;
}
void del(int a)
{
f[a] = ++n;
ar[n] = n;
}
void init()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<=n;i++)
ar[i] = f[i] = i;
int ans1 = 0,ans2 = 0;
char s[10];
int a,b;
while(true)
{
scanf("%s",s);
if(s[0] == 'e') break;
else if(s[0] == 'c')
{
int x,y;
PT(x,y);
a = find(f[x]);
b = find(f[y]);
uns(a,b);
}
else if(s[0]=='q')
{
int x,y;
PT(x,y);
a = find(f[x]);
b = find(f[y]);
if(a==b) ans1++;
else ans2++;
}
else
{
int x;
PF(x);
del(x);
}
}
printf("%d , %d\n",ans1,ans2);
}
return ;
}
int main()
{
init();
return 0;
}