This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, m; vector<char> A; vector<int> in[20005];
void set0(vector<char> &X, int i){
X[i] = '0';
for (auto nxt : in[i]) if (X[nxt] != '0') set0(X, nxt);
}
int main(){
cin >> n >> m; A.resize(n + m);
for (int i = 0; i < n + m; i++){
if (i < n) A[i] = '?';
else cin >> A[i];
}
for (int i = n, u, v; i < n + m; i++){
string a, b; cin >> a >> b;
u = a[1] - '1' + (a[0] == 'c' ? n : 0);
v = b[1] - '1' + (b[0] == 'c' ? n : 0);
in[i].push_back(u); in[i].push_back(v);
}
for (int i = n; i < n + m; i++) if (A[i] == '0') set0(A, i);
for (int i = n; i < n + m; i++){
if (A[i] == '?'){
bool ok = 1; vector<char> tmp = A; set0(tmp, i);
for (int x = n; x < n + m; x++){
char &in1 = tmp[in[x][0]], &in2 = tmp[in[x][1]], &cur = tmp[x];
if (in1 == '0' and in2 == '0') cur = '0';
if (in1 == '1' or in2 == '1') cur = '1';
if (A[x] != '?' and cur != A[x]){ ok = 0; break; }
}
cout<<(ok ? '?' : '1');
}
else cout<<A[i];
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |