# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1039207 | Soumya1 | Toy Train (IOI17_train) | C++17 | 11 ms | 3508 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 mxN = 5005;
set<int> ad[mxN], rev[mxN];
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
int n = a.size();
for (int i = 0; i < u.size(); i++) {
ad[u[i]].insert(v[i]);
rev[v[i]].insert(u[i]);
}
auto get = [&](vector<int> s) {
vector<int> out(n), vis(n);
for (int i : s) vis[i] = true;
for (int i = 0; i < s.size(); i++) {
int u = s[i];
for (int v : rev[u]) {
out[v]++;
if (!vis[v] && out[v] >= (a[v] ? 1 : ad[v].size())) {
s.push_back(v);
vis[v] = true;
}
}
}
return s;
};
vector<bool> removed(n);
while (true) {
vector<int> on;
for (int i = 0; i < n; i++) {
if (r[i] && !removed[i]) on.push_back(i);
}
vector<bool> can(n);
on = get(on);
for (int i : on) can[i] = true;
vector<int> bad;
for (int i = 0; i < n; i++) {
if (!removed[i] && !can[i]) bad.push_back(i);
}
bad = get(bad);
if (bad.empty()) break;
for (int i : bad) {
removed[i] = true;
ad[i].clear();
for (int j : ad[i]) rev[j].erase(i);
for (int j : rev[i]) ad[j].erase(i);
rev[i].clear();
}
}
vector<int> ans(n);
for (int i = 0; i < n; i++) ans[i] = !removed[i];
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... |