# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
57448 | top34051 | Toy Train (IOI17_train) | C++17 | 403 ms | 6748 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>
using namespace std;
const int maxn = 5e3 + 5;
int n,m;
int own[maxn], good[maxn];
vector<int> way[maxn], yaw[maxn];
int vis[maxn], deg[maxn];
queue<int> q;
int res[maxn];
void solve(int st) {
// printf("solve\n");
for(int i=0;i<n;i++) vis[i] = deg[i] = 0;
q.push(st);
while(!q.empty()) {
int v = q.front(); q.pop();
if(v==st && vis[v]) continue;
for(auto u : yaw[v]) {
if(own[u]) {
if(!vis[u]) {
vis[u] = 1;
q.push(u);
}
}
else {
deg[u]++;
if(!vis[u] && deg[u]==way[u].size()) {
vis[u] = 1;
q.push(u);
}
}
}
}
if(vis[st]) {
for(int i=0;i<n;i++) res[i] |= vis[i];
}
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = (int)a.size();
for(int i=0;i<n;i++) {
own[i] = a[i];
good[i] = r[i];
}
m = (int)u.size();
for(int i=0;i<m;i++) {
way[u[i]].push_back(v[i]);
yaw[v[i]].push_back(u[i]);
}
for(int i=0;i<n;i++) if(good[i]) solve(i);
vector<int> ret;
for(int i=0;i<n;i++) ret.push_back(res[i]);
return ret;
}
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... |