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
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
using namespace std;
int main()
{
    int n,q,i,index1,index2,j=0;
    cin>>n>>q;
    char znak;

    char*tab=new char[n]();
    char*tab1=new char[q]();
    for(i=0;i<n;i++)
        tab[i]=0;

    for(i=0;i<q;i++)
    {
        cin>>znak;
        if(znak=='+')
        {
            cin>>index1>>index2;
            if(index1==index2)
                tab[index1]='1';
            else
            tab[index1]='?';
            tab[index2]='?';
        }

        if(znak=='-')
        {
            cin>>index1;
            tab[index1]=0;
        }

        if(znak=='?')
        {
            cin>>index1;
            tab1[j]=tab[index1];
            j++;
        }
    }

    for(i=0;i<j;i++)
    {
        if((tab1[i]=='?')||(tab1[i]=='+')||(tab1[i]=='-'))
            cout<<tab1[i]<<" ";
        else
            break;
    }

    delete[]tab;
    delete[]tab1;

    return 0;
}