# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1070780 | Ahmed57 | Toy Train (IOI17_train) | C++17 | 6 ms | 1648 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> who_wins(vector<int> a,vector<int> r,vector<int> u,vector<int> v){
int n = a.size();
int m = u.size();
vector<int> adj[n+1],rev[n+1];
for(int i = 0;i<u.size();i++){
adj[u[i]].push_back(v[i]);
rev[v[i]].push_back(u[i]);
}
vector<int> ans(n,1);
int deg[n+1] = {0};
int vis[n+1] = {0};
while(1){
for(int i = 0;i<n;i++){
if(ans[i]){
vis[i] = 0;
deg[i] = adj[i].size();
}
}
queue<int> q;
for(int i = 0;i<n;i++){
if(ans[i]&&r[i]){
vis[i] = 1;
q.push(i);
}
}
while(!q.empty()){
int x = q.front();q.pop();
for(auto i:rev[x]){
deg[i]--;
if(ans[i]&&(deg[i]==0||a[i]==1)&&!vis[i]){
vis[i] = 1;
q.push(i);
}
}
}
bool upd = 0;
for(int i = 0;i<n;i++){
int old = ans[i];
ans[i]&=vis[i];
if(old!=ans[i])upd = 1;
}
if(upd==0)break;
}
return ans;
}
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... |