# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1061220 | vjudge1 | Toy Train (IOI17_train) | C++17 | 99 ms | 25924 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 N = 5000 + 10;
vector<int> G[N];
bool R[N], seen[N][N];
int n;
bool dfs(int v, int s)
{
seen[v][s] = true;
if(R[v]) return 1;
bool ok = 0;
for(int u : G[v])
{
if(seen[u][s]) continue;
ok |= dfs(u, s);
}
return ok;
}
vector<int> Arezou()
{
vector<int> w(n);
for(int s = 0; s < n; s++)
w[s] = dfs(s, s);
return w;
}
vector<int> Borzou()
{
vector<int> w(n);
return w;
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v)
{
n = a.size();
for(int i = 0; i < u.size(); i ++)
G[u[i]].push_back(v[i]);
for(int i = 0; i < n; i ++)
R[i] = r[i];
vector<int> w(n);
int c = count(a.begin(), a.end(), 1);
if(c == a.size())
return Arezou();
if(c == 0)
return Borzou();
for(int i = 0; i < n; i++)
{
int s = i;
while(true)
{
// do I have a cycle
bool cycle = false;
for(int c : G[s])
if(c == s) cycle = true;
if(cycle && r[s] && (G[s].size() == 1 || a[s] == 1))
{
w[i] = 1;
break;
}
if(cycle && G[s].size() == 1)
break;
s++;
}
}
return w;
}
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... |