# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
970450 | Itamar | Toy Train (IOI17_train) | C++14 | 1331 ms | 1876 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 <vector>
using namespace std;
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#include <algorithm>
#define x first
#define y second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vb vector<bool>
int n, m;
const int siz = 5e3 + 1;
vi fr[siz];
vi invf[siz];
#include <queue>
int a[siz];
int deg[siz];
void func(vi& bad) {
vector<bool> vis(n);
queue<int> q;
for (int i = 0; i < n; i++)if (bad[i])q.push(i);
for (int i = 0; i < n; i++)deg[i] = fr[i].size();
while (!q.empty()) {
int i = q.front();
q.pop();
if (vis[i])continue;
vis[i] = 1;
bad[i] = 1;
for (int f : invf[i]) {
if (vis[f])continue;
deg[f]--;
if (a[f] == 1) {
if (deg[f] == fr[f].size() - 1)q.push(f);
}
else {
if (deg[f] == 0)q.push(f);
}
}
}
}
vi who_wins(vi A, vi R, vi U, vi V) {
n = R.size(), m = U.size();
for (int i = 0; i < n; i++)a[i] = A[i];
for (int i = 0; i < m; i++) {
fr[U[i]].push_back(V[i]);
invf[V[i]].push_back(U[i]);
}
vi bad(n,1);
for (int it = 0; it <= n; it++) {
vi badt(n);
/*for (int i = 0; i < n; i++) {
//if (bad[i]) {
if (A[i]) {
bool g = 0;
for (int j : fr[i])g |= bad[j];
if (g == 0)badt[i] = 0;
else badt[i] = 1;
}
else {
for (int j : fr[i]) {
if (bad[j] == 0) {
badt[i] = 0;
break;
}
if (j == fr[i].back())badt[i] = 1;
}
}
//}
}*/
//bad = badt;
vi badtt = R; for (int i = 0; i < n; i++)if (bad[i] == 0)badtt[i] = 0;
func(badtt);
for (int i = 0; i < n; i++)if (badtt[i] == 0)bad[i] = 0;
}
return bad;
}
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... |