# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
227770 | AaronNaidu | Toy Train (IOI17_train) | C++14 | 89 ms | 2048 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;
vector<int> a, r, f;
vector<int> graph[6000];
vector<int> rgraph[6000];
vector<bool> visited;
int givesAWin[6000];
pair<bool, int> inCycle[6000];
vector<int> DFSpath;
vector<int> goodsInPath;
queue<int> q;
bool cycleTime(int node, int orig) {
if (r[node])
{
return true;
}
if (node == orig)
{
return false;
}
return cycleTime(f[node], orig);
}
void checkForCycle(int node, int starter, bool atStart) {
// cout << "Checking " << node << "\n";
if (inCycle[node].first and (goodsInPath.size() == 0 or inCycle[node].second > goodsInPath[goodsInPath.size() - 1]))
{
//cout << "In the cycle\n";
for (int i = 0; i < DFSpath.size(); i++)
{
//cout << DFSpath[i] << " gives a win\n";
if (!givesAWin[DFSpath[i]])
{
q.push(DFSpath[i]);
}
givesAWin[DFSpath[i]] = true;
}
//cout << "Leaving " << node << "\n";
return;
}
if (visited[node])
{
//cout << "Already visited\n";
if (givesAWin[node])
{
// cout << "Known to give a win\n";
for (auto i : DFSpath)
{
// cout << DFSpath[i] << " gives a win\n";
if (!givesAWin[i])
{
q.push(i);
}
givesAWin[i] = true;
}
}
// cout << "Leaving " << node << "\n";
return;
}
inCycle[node] = {true, DFSpath.size()};
if (r[node])
{
// cout << node << " is a charging station\n";
goodsInPath.push_back(DFSpath.size());
}
visited[node] = true;
DFSpath.push_back(node);
for (auto i : graph[node])
{
checkForCycle(i, starter, atStart);
}
inCycle[node].first = false;
DFSpath.pop_back();
if (r[node])
{
goodsInPath.pop_back();
}
// cout << "Leaving " << node << "\n";
}
vector<int> who_wins(vector<int> la, vector<int> lr, vector<int> lu, vector<int> lv) {
a = la;
r = lr;
for (int i = 0; i < lu.size(); i++)
{
graph[lu[i]].push_back(lv[i]);
rgraph[lv[i]].push_back(lu[i]);
}
for (int i = 0; i < a.size(); i++)
{
f.push_back(-1);
visited.push_back(false);
}
for (int i = 0; i < r.size(); i++)
{
if (!r[i])
{
checkForCycle(i, i, true);
}
}
while (!q.empty())
{
int x = q.front();
q.pop();
for (auto i : rgraph[x])
{
if (!givesAWin[i])
{
givesAWin[i] = true;
q.push(i);
}
}
}
vector<int> toRet;
for (int i = 0; i < a.size(); i++)
{
toRet.push_back(!givesAWin[i]);
}
return toRet;
}
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... |