# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
715952 | Ahmed57 | Ili (COI17_ili) | C++14 | 4 ms | 4948 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 <bits/stdc++.h>
using namespace std;
vector<int> adj[200001];
int n,m;
int num(string s){
int add = 0;
if(s[0]=='c')add = n;
long long ans = 0;
for(int i = 1;i<s.size();i++){
ans=ans*10+(s[i]-'0');
}
return ans+add;
}
signed main(){
//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>m;
string s;cin>>s;
for(int i = 1;i<=m;i++){
string a1,a2;cin>>a1>>a2;
adj[i+n].push_back(num(a1));
adj[i+n].push_back(num(a2));
}
queue<int> q;
int ze[n+m+5] = {0};
int on[n+m+5] = {0};
for(int i = 0;i<s.size();i++){
if(s[i]=='0'){
q.push(i+n+1);
ze[i+n+1] = 1;
}else if(s[i]=='1'){
on[i+n+1] = 1;
}
}
while(!q.empty()){
int w = q.front();q.pop();
for(auto j:adj[w]){
if(!ze[j]){
ze[j] = 1;
q.push(j);
}
}
}
for(int i = n+1;i<=n+m;i++){
if(s[i-n-1]=='1'){
if(ze[adj[i][0]]){
on[adj[i][1]] = 1;
}else if(ze[adj[i][1]]){
on[adj[i][0]] = 1;
}
}if(s[i-n-1]=='?'){
if(ze[adj[i][0]]&&ze[adj[i][1]])ze[i] = 1;
}
}
for(int i = 0;i<s.size();i++)s[i] = '?';
bitset<20001> v[n+m+1];
vector<int> ones;
for(int i =1 ;i<=n;i++){
v[i][i] = 1;
if(on[i]){
ones.push_back(i);
}
}
for(int i = n+1;i<=n+m;i++){
v[i] = (v[adj[i][0]]^v[adj[i][1]]);
bool o = on[i],z = ze[i];
for(auto j:ones){
if((v[j]&v[i]).count()==v[j].count()){
o = 1;
break;
}
}
o|=on[i];
if(o&&z||(!o&&!z)){
cout<<'?';
continue;
}
if(z){
cout<<'0';
}
if(o){
cout<<'1';
ones.push_back(i);
}
}
}
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... |