이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "train.h"
#include <algorithm>
#include <vector>
using namespace std;
const int maxN = 5000;
vector<int> nei[maxN];
int charge[maxN], a[maxN];
int ans[maxN];
int col[maxN], isCyc[maxN];
int n;
vector<int> rnei[maxN];
bool used1[maxN];
void DFS1(int v, vector<int>& sorted)
{
used1[v] = true;
for (int to: nei[v])
if (!used1[to])
DFS1(to, sorted);
sorted.push_back(v);
}
void DFS2(int v, int curcol)
{
col[v] = curcol;
for (int to: rnei[v])
if (!col[to])
{
DFS2(to, curcol);
isCyc[curcol] = true;
}
else if (col[to] == curcol)
isCyc[curcol] = true;
}
void SCC()
{
for (int v = 0; v < n; ++v)
for (int to: nei[v])
rnei[to].push_back(v);
vector<int> sorted;
for (int i = 0; i < n; ++i)
if (!used1[i])
DFS1(i, sorted);
reverse(sorted.begin(), sorted.end());
int cols = 0;
for (int v: sorted)
if (!col[v])
DFS2(v, ++cols);
}
bool used3[maxN];
void DFS3(int v)
{
used3[v] = true;
ans[v] = 1;
for (int to: rnei[v])
if (!used3[to])
DFS3(to);
}
vector<int> Solve3()
{
SCC();
vector<bool> goodcol(n);
for (int v = 0; v < n; ++v)
if (charge[v])
goodcol[col[v]] = true;
for (int v = 0; v< n; ++v)
if (goodcol[col[v]] && isCyc[col[v]] && !used3[v])
DFS3(v);
return vector<int>(ans, ans + n);
}
vector<int> Solve4()
{
SCC();
}
std::vector<int> who_wins(std::vector<int> a_, std::vector<int> charge_, std::vector<int> u, std::vector<int> v) {
n = a_.size();
for (int i = 0; i < n; ++i)
a[i] = a_[i], charge[i] = charge_[i];
for (int i = 0; i < u.size(); ++i)
nei[u[i]].push_back(v[i]);
if (!count(a, a + n, 0))
return Solve3();
}
컴파일 시 표준 에러 (stderr) 메시지
train.cpp: In function 'std::vector<int> Solve4()':
train.cpp:74:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:79:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < u.size(); ++i)
~~^~~~~~~~~~
train.cpp:83:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | 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... |