#include <iostream> #include <vector> using namespace std; int n, q; char tab[300010]; vector<int> v[300010]; void f(int a) { for(auto x : v[a]) { tab[x] = '1'; } v[a].clear(); } int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); for(int i=0;i<300010;++i) tab[i] = '0'; cin >> n >> q; while(q--) { char c; int a, b; cin >> c; if(c == '?') { cin >> a; cout << tab[a]; } if(c == '+') { cin >> a >> b; if(a == b) { f(a); tab[a] = '1'; continue; } if((tab[a] == '?' && tab[b] == '0') || (tab[a] == '0' && tab[b] == '?') || (tab[a] == '0' && tab[b] == '0')) { if(tab[a] == '?') v[a].push_back(b); else if(tab[b] == '?') v[b].push_back(a); tab[a] = '?'; tab[b] = '?'; } else { tab[a] = '1'; tab[b] = '1'; } } if(c == '-') { cin >> a; f(a); tab[a] = '0'; } } return 0; }
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 | #include <iostream> #include <vector> using namespace std; int n, q; char tab[300010]; vector<int> v[300010]; void f(int a) { for(auto x : v[a]) { tab[x] = '1'; } v[a].clear(); } int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); for(int i=0;i<300010;++i) tab[i] = '0'; cin >> n >> q; while(q--) { char c; int a, b; cin >> c; if(c == '?') { cin >> a; cout << tab[a]; } if(c == '+') { cin >> a >> b; if(a == b) { f(a); tab[a] = '1'; continue; } if((tab[a] == '?' && tab[b] == '0') || (tab[a] == '0' && tab[b] == '?') || (tab[a] == '0' && tab[b] == '0')) { if(tab[a] == '?') v[a].push_back(b); else if(tab[b] == '?') v[b].push_back(a); tab[a] = '?'; tab[b] = '?'; } else { tab[a] = '1'; tab[b] = '1'; } } if(c == '-') { cin >> a; f(a); tab[a] = '0'; } } return 0; } |