#include "train.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
const int n = (int)a.size(), m = (int)u.size();
std::vector<std::vector<int>> graph(n);
for (int i = 0; i < m; ++i) {
graph[u[i]].push_back(v[i]);
}
// subtask 4
int chargingS = -1;
for (int i = 0; i < n; ++i) {
if (r[i] == 1) {
if (chargingS == -1) {
chargingS = i;
} else {
assert(false);
}
}
}
std::vector<int> reachableV(n, -1);
reachableV[chargingS] = 1;
for (int i = 0; i < n; ++i) {
auto itr = std::find(graph[i].begin(), graph[i].end(), i);
if (r[i] == 0 and a[i] == 0 and itr != graph[i].end()) {
reachableV[i] = 0;
}
}
for (int x = 0; x < 2 * n; ++x) {
for (int i = 0; i < n; ++i) {
if (reachableV[i] != -1) {
continue;
}
if (a[i] == 1) {
bool isOk = false, isRa = true;
for (const int t : graph[i]) {
if (reachableV[t] == 1) {
isOk = true;
}
if (reachableV[t] == -1) {
isRa = false;
}
}
if (isOk) {
reachableV[i] = 1;
} else if (isRa) {
reachableV[i] = 0;
}
} else {
bool isOk = true, isRa = true;
for (const int t : graph[i]) {
if (reachableV[t] != 1) {
isOk = false;
}
if (reachableV[t] == -1) {
isRa = false;
}
}
if (isOk) {
reachableV[i] = 1;
} else if (isRa) {
reachableV[i] = 0;
}
}
}
}
for (auto &e : reachableV) {
if (e == -1) {
e = 0;
}
}
reachableV[chargingS] = -1;
if (a[chargingS] == 1) {
bool isOk = false;
for (const int t : graph[chargingS]) {
if (reachableV[t] == 1) {
isOk = true;
} else if (t == chargingS) {
isOk = true;
}
}
if (isOk) {
reachableV[chargingS] = 1;
} else {
reachableV[chargingS] = 0;
}
} else {
bool isOk = true;
for (const int t : graph[chargingS]) {
if (reachableV[t] == 0) {
isOk = false;
}
}
if (isOk) {
reachableV[chargingS] = 1;
} else {
reachableV[chargingS] = 0;
}
}
std::vector<int> answer(n);
for (int i = 0; i < n; ++i) {
answer[i] = (reachableV[i] == 1 and reachableV[chargingS] == 1) ? 1 : 0;
}
return answer;
}
/*
using namespace std;
int main() {
int n, m;
assert(2 == scanf("%d %d", &n, &m));
vector<int> a(n), r(n), u(m), v(m);
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &a[i]));
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &r[i]));
for(int i = 0; i < m; i++)
assert(2 == scanf("%d %d", &u[i], &v[i]));
vector<int> res = who_wins(a, r, u, v);
for(int i = 0; i < (int)res.size(); i++)
printf(i ? " %d" : "%d", res[i]);
printf("\n");
return 0;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
1460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
2100 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
1760 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
765 ms |
1228 KB |
Output is correct |
2 |
Correct |
41 ms |
1204 KB |
Output is correct |
3 |
Correct |
345 ms |
1236 KB |
Output is correct |
4 |
Correct |
39 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
302 ms |
836 KB |
Output is correct |
7 |
Correct |
22 ms |
892 KB |
Output is correct |
8 |
Correct |
38 ms |
820 KB |
Output is correct |
9 |
Correct |
36 ms |
908 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
11 ms |
820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
1460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |