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<bool> visited;
int givesAWin[6000];
pair<bool, int> inCycle[6000];
vector<int> DFSpath;
vector<int> goodsInPath;
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 (atStart)
{
//cout << "At start\n";
goodsInPath.push_back(0);
visited[node] = true;
DFSpath.push_back(node);
inCycle[node] = {true, 0};
for (auto i : graph[node])
{
checkForCycle(i, starter, false);
}
inCycle[node].first = false;
DFSpath.pop_back();
goodsInPath.pop_back();
//cout << "Leaving " << node << "\n";
return;
}
if (inCycle[node].first and 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";
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";
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]);
}
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] == 1)
{
checkForCycle(i, i, true);
}
}
vector<int> toRet;
for (int i = 0; i < a.size(); i++)
{
toRet.push_back(givesAWin[i]);
}
return toRet;
}
Compilation message (stderr)
train.cpp: In function 'void checkForCycle(int, int, bool)':
train.cpp:46:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < DFSpath.size(); i++)
~~^~~~~~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:94:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < lu.size(); i++)
~~^~~~~~~~~~~
train.cpp:98:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a.size(); i++)
~~^~~~~~~~~~
train.cpp:103:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < r.size(); i++)
~~^~~~~~~~~~
train.cpp:111:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a.size(); i++)
~~^~~~~~~~~~
# | 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... |