이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "train.h"
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define INF (1LL<<60)
#define _1 first
#define _2 second
using namespace std;
typedef pair<int, int> P;
int N, M;
vector<int> G[5000], R[5000];
vector<int> who_wins(vector<int> owner, vector<int> color, vector<int> U, vector<int> V) {
N = owner.size(), M = U.size();
vector<int> used(N);
rep(i, M) G[U[i]].pb(V[i]), R[V[i]].pb(U[i]);
bool allA = true, allB = true;
for (int x : owner) if (x == 0) allA = false; else allB = false;
queue<int> win;
if (allA) {
rep(s, N) {
if (color[s] != 1) continue;
rep(x, N) used[x] = false;
queue<int> q;
q.push(s);
while (!q.empty()) {
int x = q.front(); q.pop();
for (int t : G[x]) if (!used[t]) {
used[t] = true;
q.push(t);
}
}
if (used[s]) win.push(s);
}
}
else if (allB) {
rep(s, N) {
if (color[s] != 0) continue;
rep(x, N) used[x] = false;
queue<int> q;
q.push(s);
while (!q.empty()) {
int x = q.front(); q.pop();
for (int t : G[x]) if (color[t] == 0 && !used[t]) {
used[t] = true;
q.push(t);
}
}
if (used[s]) win.push(s);
}
}
else abort();
rep(i, N) used[i] = false;
while (!win.empty()) {
int x = win.front(); win.pop();
if (used[x]) continue;
used[x] = true;
for (int t : R[x]) win.push(t);
}
return used;
}
# | 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... |