1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//泥の分際で私だけの大切を奪おうだなん
#include<bits/stdc++.h>
using namespace std;
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int fa[1300003],a[1300003],b[1300003],lst[300003];
inline int find(int x){return (fa[x]==x)?x:(fa[x]=find(fa[x]));}
signed main()
{
	int n=read(),m=read();
	for(int i=1; i<=n+m; ++i) fa[i]=i,a[i]=1;
	for(int i=1; i<=n; ++i) lst[i]=i;
	for(int i=n+1,x,y; i<=n+m; ++i)
	{
		char c=getchar();
		while(c!='?'&&c!='+'&&c!='-') c=getchar();
		if(c=='?')
		{
			x=find(lst[read()]);
			if(a[x]==b[x]) putchar('1');
			else if(a[x]>1) putchar('?');
			else putchar('0');
			
		}
		else if(c=='+')
		{
			x=find(lst[read()]),y=find(lst[read()]);
			if(x!=y) fa[x]=y,a[y]+=a[x],b[y]+=b[x];
			++b[y];
		}
		else
			x=read(),y=find(lst[x]),
			--a[y],--b[y],lst[x]=i;
	}
	return 0;
}