# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
592468 | franfill | Toy Train (IOI17_train) | C++17 | 889 ms | 1716 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<queue>
#include<iostream>
using namespace std;
vector<int> who_wins(vector<int> a, vector<int> re, vector<int> u, vector<int> v) {
int n = a.size(), m = u.size();
vector < vector < int > > g(n);
vector < vector < int > > r(n);
for (int i = 0; i < m; i++)
{
g[u[i]].emplace_back(v[i]);
r[v[i]].emplace_back(u[i]);
}
vector < bool > used(n, 0);
while(true)
{
vector < bool > good(n);
queue < int > q;
for (int i = 0; i < n; i++) if (!used[i])
{
if (re[i])
{
good[i] = true;
q.emplace(i);
}
}
vector < int > cnt(n, 0);
for (int x = 0; x < n; x++)
{
for (auto y : g[x]) if (used[y])
{
cnt[x]++;
}
}
while(!q.empty())
{
int x = q.front();
q.pop();
for (auto y : r[x]) if (!used[y] && !good[y])
{
cnt[y]++;
if (a[y] || cnt[y] == g[y].size())
{
good[y] = true;
q.emplace(y);
}
}
}
cnt.assign(n, 0);
for (int x = 0; x < n; x++)
{
for (auto y : g[x]) if (used[y])
{
cnt[x]++;
}
}
bool ok = true;
for (int x = 0; x < n; x++) if (!used[x] && !good[x])
{
used[x] = true;
q.push(x);
ok = false;
}
if (ok) break;
while(!q.empty())
{
int x = q.front();
q.pop();
for (auto y : r[x]) if (!used[y])
{
cnt[y]++;
if (!a[y] || cnt[y] == g[y].size())
{
used[y] = true;
q.emplace(y);
}
}
}
}
vector < int > ans;
for (auto b : used)
{
if (b) ans.emplace_back(0);
else ans.emplace_back(1);
}
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... |