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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// lidB.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>

typedef std::vector<char> stanKomputeraLudu;

void dodKomp(stanKomputeraLudu& stanK, const int komp1, const int komp2 )
{
	if (komp1 == komp2) {
		stanK[komp1] = 2;
		return;
	}

	if ((stanK[komp1] | stanK[komp2]) & 2) {//if any one of those has PC, then treat them both fulfilled
		stanK[komp1] = 2;
		stanK[komp2] = 2;
		return;
	}

	if (stanK[komp1] >= 1 && stanK[komp2] >= 1) {
		stanK[komp1] = 2;
		stanK[komp2] = 2;
		return;
	}
	//if any one does not have PC, then we are unsure
	stanK[komp1] = 1;
	stanK[komp2] = 1;
}

int main()
{
	stanKomputeraLudu stanK;

	 ///ilosc mieszkancow >= 1
	int arg_n;
	 ///ilosc modyfikacji >= 1
	int arg_q;
	std::cin >> arg_n;
	std::cin >> arg_q;
	stanK.resize(arg_n+1, 0);

	char znaczek;
	int komp1;
	int komp2;

	for (int i = 0; i != arg_q; ++i) {
		std::cin >> znaczek;
		std::cin >> komp1;
		if (znaczek == '+') {
			std::cin >> komp2;
			dodKomp(stanK, komp1, komp2);
		}
		else if (znaczek == '-') {
			stanK[komp1] = 0;
		}
		else if (znaczek == '?') {
			auto stanKomp = stanK[komp1];
			if (stanKomp == 2) {
				std::cout << "1";
			} else if (stanKomp == 0) {
				std::cout << "0";
			} else {
				std::cout << "?";
			}
		}

	}
	return 0;
}