# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95257 | andy627 | Toy Train (IOI17_train) | C++17 | 534 ms | 1892 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 "train.h"
#include <bits/stdc++.h>
#define N 5005
using namespace std;
vector<int>g[N],rev[N];
bool f[N],iq[N],ans[N],ig[N];int goal[N],fc[N],a[N];
int n,m,k;
void getfunx(int t) // calculate function : t=1 then A, t=0 then B result : bool array f
{
for(int i=0;i<n;i++)
fc[i]=iq[i]=0;
queue<int>que;
for(int i=0;i<n;i++){
if(!ig[i]&&f[i]){
iq[i]=true;
que.push(i);
}
}
while(que.size()){
int i=que.front();
que.pop();
f[i]=true;
for(auto &it : rev[i]){
if(ig[it])
continue;
fc[it]++;
if(iq[it])
continue;
if(a[it]==t){
iq[it]=true;
que.push(it);
}
else if(fc[it]==goal[it]){
iq[it]=true;
que.push(it);
}
}
}
}
vector<int> who_wins(vector<int> A,vector<int> r,vector<int> u,vector<int> v)
{
n=A.size(),m=u.size(),k=r.size();
for(int i=0;i<n;i++)
a[i]=A[i];
vector<int> res(n);
for(int i=0;i<m;i++){
g[u[i]].push_back(v[i]);
goal[u[i]]++;
rev[v[i]].push_back(u[i]);
}
while(1){
for(int i=0;i<n;i++)
if(!ig[i])
f[i]=r[i];
getfunx(1);
bool isans=true;
for(int i=0;i<n;i++){
if(ig[i])
continue;
if(!f[i])
isans=false;
f[i]=!f[i];
}
if(isans){
for(int i=0;i<n;i++)
if(!ig[i])
ans[i]=true;
break;
}
getfunx(0);
for(int i=0;i<n;i++){
if(!ig[i]&&f[i]){
ig[i]=true;
for(auto &it : rev[i])
goal[it]--;
}
}
}
for(int i=0;i<n;i++)
res[i]=ans[i];
return res;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |