이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
#define all(aaa) aaa.begin(), aaa.end();
#define ll long long
const int N = 5005;
vector<int> g[N];
int deg[N], tmp[N];
bool used[N];
int n, m;
vector<int> reachable(vector<int> &a, vector<int> v, int master) {
for (int i = 0; i < n; i++) {
used[i] = 0;
tmp[i] = deg[i];
}
queue<int> q;
auto check = [&](int x) {
if (!used[x]) {
if (a[x] == master) {
used[x] = 1;
q.push(x);
}
else if (--tmp[x] == 0) {
used[x] = 1;
q.push(x);
}
}
};
for (int x : v) {
used[x] = 1;
q.push(x);
}
for (int x : v) {
for (int to : g[x]) {
check(to);
}
}
while (!q.empty()) {
int node = q.front();
q.pop();
for (int to : g[node]) {
check(to);
}
}
vector<int> ans;
for (int i = 0; i < n; i++) {
if (used[i])
ans.push_back(i);
}
return ans;
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = a.size(), m = u.size();
for (int i = 0; i < m; i++) {
g[v[i]].push_back(u[i]);
deg[u[i]]++;
}
vector<int> res(n, 1);
bool work = true;
while (work) {
work = false;
vector<int> sts;
for (int i = 0; i < n; i++) {
if (r[i])
sts.push_back(i);
}
vector<int> good = reachable(a, sts, 1), killers;
for (int i = 0, j = 0; i < n; i++) {
while (j < good.size() && good[j] < i)
j++;
if (j == good.size() ||
good[j] != i)
killers.push_back(i);
}
vector<int> bad = reachable(a, killers, 0);
for (int x : bad) {
if (r[x])
work = true;
res[x] = 0;
r[x] = 0;
}
}
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:89:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (j < good.size() && good[j] < i)
~~^~~~~~~~~~~~~
train.cpp:91:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (j == good.size() ||
~~^~~~~~~~~~~~~~
# | 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... |