# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
58643 | reality | Toy Train (IOI17_train) | C++17 | 667 ms | 25032 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;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
#include "train.h"
vi answer;
int n;
const int N = 1e6;
vi G[N];
int deg[N];
int d[N];
vi who;
void dfs(int node) {
for (auto it : G[node]) {
--deg[it];
if (!deg[it] && who[it])
dfs(it);
}
}
vi who_wins(vi a, vi b, vi u, vi v) {
n = a.size();
for (auto & it : b)
it ^= 1;
who = b;
for (int i = 0;i < u.size();++i)
G[v[i]].pb(u[i]),++d[u[i]];
answer.resize(n);
for (int i = 0;i < n;++i)
answer[i] = 1;
int ok;
do {
ok = 0;
who = b;
for (int i = 0;i < n;++i)
deg[i] = a[i] ? 1 : d[i];
for (int i = 0;i < n;++i)
if (!who[i] && answer[i])
dfs(i);
for (int i = 0;i < n;++i) {
if (!who[i] && answer[i] && deg[i] > 0)
ok = 1,answer[i] = 0;
answer[i] &= deg[i] <= 0;
}
} while (ok);
return answer;
}
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... |