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;
#define rep(i, j, k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
typedef vector<int> vi;
vi who_wins(vi a, vi r, vi u, vi v) {
int n = a.size();
int m = u.size();
vector<vi> adj(n), radj(n);
rep(i, 0, m) {
adj[u[i]].pb(v[i]);
radj[v[i]].pb(u[i]);
}
vector<bool> dead(n);
rep(z, 0, n) {
fill(all(dead), 0);
int L = 0, R = 0;
vi q(n), cnt(n);
rep(i, 0, n) if (r[i]) {
dead[i] = true;
q[R++] = i;
}
while (L < R) {
int me = q[L++];
for (auto e : radj[me]) {
if (dead[e]) continue;
cnt[e]++;
if (a[e] || cnt[e] == adj[e].size()) {
dead[e] = true;
q[R++] = e;
}
}
}
L = R = 0;
fill(all(cnt), 0);
rep(i, 0, n) for (auto e : adj[i]) if (!dead[e]) cnt[i]++;
rep(i, 0, n) if (cnt[i] && (!a[i] || cnt[i] == adj[i].size())) {
dead[i] = false;
q[R++] = i;
}
while (L < R) {
int me = q[L++];
for (auto e : radj[me]) {
if (!dead[e]) continue;
cnt[e]++;
if (!a[e] || cnt[e] == adj[e].size()) {
q[R++] = e;
dead[e] = false;
}
}
}
rep(i, 0, n) if (!dead[i]) r[i] = 0;
}
vi res(n);
rep(i, 0, n) if (dead[i]) res[i] = 1;
return res;
}
Compilation message (stderr)
train.cpp: In function 'vi who_wins(vi, vi, vi, vi)':
train.cpp:39:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (a[e] || cnt[e] == adj[e].size()) {
train.cpp:51:49: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
rep(i, 0, n) if (cnt[i] && (!a[i] || cnt[i] == adj[i].size())) {
train.cpp:61:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (!a[e] || cnt[e] == adj[e].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... |