# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
245718 | vanic | Ili (COI17_ili) | C++14 | 7 ms | 1920 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 <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <bitset>
using namespace std;
const int maxn=2e4+5;
vector < int > ms[maxn];
vector < int > up[maxn];
vector < int > boje[maxn];
int kol[maxn];
int val[maxn];
int pretvori(string x){
int br=0;
for(int i=1; i<x.size(); i++){
br*=10;
br+=x[i]-'0';
}
return br;
}
void probaj(int x);
void gore(int x){
val[x]=1;
probaj(x);
for(int i=0; i<up[x].size(); i++){
if(val[up[x][i]]==-1){
gore(up[x][i]);
}
}
}
void dolje(int x){
val[x]=0;
for(int i=0; i<ms[x].size(); i++){
if(val[ms[x][i]]==-1){
dolje(ms[x][i]);
}
}
for(int i=0; i<up[x].size(); i++){
if(ms[up[x][i]].size()==1 && val[up[x][i]]==-1){
dolje(up[x][i]);
}
else if(val[up[x][i]]==-1 && !val[ms[up[x][i]][0]] && !val[ms[up[x][i]][1]]){
dolje(up[x][i]);
}
}
}
void probaj(int x){
val[x]=1;
if(ms[x].size()==1){
if(val[ms[x][0]]==-1){
gore(ms[x][0]);
}
}
else if(ms[x].size()==2){
if(!val[ms[x][0]] && val[ms[x][1]]==-1){
gore(ms[x][1]);
}
else if(!val[ms[x][1]] && val[ms[x][0]]==-1){
gore(ms[x][0]);
}
}
}
bitset < maxn > bio;
bitset < maxn > sad;
void dfs(int x){
bio[x]=1;
sad[x]=1;
for(int i=0; i<up[x].size(); i++){
if(val[up[x][i]]!=1){
if(bio[up[x][i]]){
if(!sad[up[x][i]]){
gore(up[x][i]);
}
}
else{
dfs(up[x][i]);
}
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
string s;
cin >> s;
string a, b;
int br1, br2;
memset(val, -1, sizeof(val));
for(int i=0; i<m; i++){
cin >> a >> b;
br1=pretvori(a);
br2=pretvori(b);
br1--;
br2--;
if(a[0]=='c'){
br1+=n;
}
if(b[0]=='c'){
br2+=n;
}
if(br1!=br2){
up[br1].push_back(i+n);
up[br2].push_back(i+n);
ms[i+n].push_back(br1);
ms[i+n].push_back(br2);
}
else{
up[br1].push_back(i+n);
ms[i+n].push_back(br1);
}
}
for(int i=0; i<m; i++){
if(val[i+n]==-1){
if(s[i]=='0'){
dolje(i+n);
}
else if(s[i]=='1'){
gore(i+n);
}
}
}
for(int i=0; i<m; i++){
if(val[i+n]==1){
probaj(i+n);
}
}
for(int i=0; i<m; i++){
if(val[i+n]==1 && val[ms[i+n][0]]==-1 && val[ms[i+n][1]]==-1){
dfs(ms[i+n][0]);
sad.reset();
if(bio[ms[i+n][1]]){
gore(ms[i+n][1]);
}
else{
dfs(ms[i+n][1]);
sad.reset();
}
bio.reset();
}
}
for(int i=0; i<m; i++){
if(val[i+n]==-1){
cout << '?';
}
else{
cout << val[i+n];
}
}
cout << '\n';
return 0;
}
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... |