# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20980 | ainta | Ili (COI17_ili) | C++14 | 2996 ms | 2680 KiB |
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<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, m, E[20100][2];
char p[10100];
vector<int> G[20100];
int Get(char *a){
int i, s = 0;
for(i=1;a[i];i++)s=s*10+a[i]-'0';
if(a[0]=='x')return s;
return s+n;
}
int v[20100];
struct point{
int a, b, c;
}w[20100];
void DFS(int a){
v[a]=1;
if(a<=n)return;
int i;
for(i=0;i<2;i++){
if(!v[E[a][i]])DFS(E[a][i]);
}
}
int Q[20100], head, tail;
int vv[20100];
bool Pos(int a, int b){
int i;
if(!a){
for(i=1;i<=n+m;i++)v[i]=0;
for(i=1;i<=m;i++){
if(p[i]=='1' && !v[n+i]) v[n+i] = 2;
}
for(i=1;i<=m;i++){
if(p[i]=='0' && !v[n+i])DFS(n+i);
}
}
else{
for(i=1;i<=n+m;i++)v[i]=vv[i];
if(b==1) DFS(a);
else v[a] = b;
}
for(i=1;i<=m;i++){
if(!v[w[i].c]){
if(v[w[i].a] == 1 && v[w[i].b] == 1) v[w[i].c] = 1;
}
}
head = tail = 0;
for(i=1;i<=n+m;i++){
if(v[i]==2)Q[++tail] = i;
}
while(head < tail){
int x = Q[++head];
if(x > n){
if(v[E[x][0]] == 1 && v[E[x][1]] == 0){
v[E[x][1]] = 2;
Q[++tail] = E[x][1];
}
if(v[E[x][1]] == 1 && v[E[x][0]] == 0){
v[E[x][0]] = 2;
Q[++tail] = E[x][0];
}
}
for(i=0;i<G[x].size();i++){
if(!v[G[x][i]]){
v[G[x][i]] = 2;
Q[++tail] = G[x][i];
}
}
}
for(i=1;i<=m;i++){
if(v[w[i].a]==1 && v[w[i].b]==1 && v[w[i].c] == 2)return false;
if((v[w[i].a]==2 || v[w[i].b]==2) && v[w[i].c] == 1)return false;
}
return true;
}
int main(){
int i;
scanf("%d%d",&n,&m);
scanf("%s",p+1);
char p1[20], p2[20];
for(i=1;i<=m;i++){
scanf("%s%s",p1,p2);
int t1 = Get(p1), t2 = Get(p2);
E[n+i][0] = t1;
E[n+i][1] = t2;
G[t1].push_back(n+i);
G[t2].push_back(n+i);
w[i].a = t1, w[i].b = t2, w[i].c = n+i;
}
DFS(0);
Pos(0,0);
for(i=1;i<=n+m;i++)vv[i] = v[i];
for(i=1;i<=m;i++){
if(vv[n+i]){
printf("%d",vv[n+i]-1);
continue;
}
if(!Pos(n+i, 1)){
printf("1");
}
else if(!Pos(n+i, 2)){
printf("0");
}
else printf("?");
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |