#include<bits/stdc++.h>
using namespace std;
#include "train.h"
vector<vector<int>> adj;
vector<bool> v;
vector<int> res;
vector<int> a, r;
bool dfs(int node){
if(res[node] != -1) return res[node];
bool b = 0;
for(auto e : adj[node]){
if(e == node) b = 1;
else{
res[node] = dfs(e);
}
}
if(res[node] == -1) res[node] = r[node];
else if(b && a[node]){
if(r[node]) res[node] = 1;
}else if(b && !a[node]){
if(!r[node]) res[node] = 0;
}
return res[node];
}
std::vector<int> who_wins(std::vector<int> ta, std::vector<int> tr, std::vector<int> u, std::vector<int> tv) {
int N = ta.size();
int M = u.size();
adj = vector<vector<int>> (N);
res = vector<int> (N, -1);
a = ta;
r = tr;
for(int i = 0; i < M; i++) {
adj[u[i]].push_back(tv[i]);
}
for(int i = 0; i < N; i++){
res[i] = dfs(i);
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1280 KB |
Output is correct |
2 |
Correct |
6 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1024 KB |
Output is correct |
4 |
Correct |
5 ms |
1024 KB |
Output is correct |
5 |
Correct |
12 ms |
1020 KB |
Output is correct |
6 |
Correct |
4 ms |
896 KB |
Output is correct |
7 |
Correct |
6 ms |
896 KB |
Output is correct |
8 |
Correct |
6 ms |
896 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
4 ms |
896 KB |
Output is correct |
11 |
Correct |
4 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
170 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1536 KB |
Output is correct |
2 |
Correct |
8 ms |
1408 KB |
Output is correct |
3 |
Correct |
8 ms |
1536 KB |
Output is correct |
4 |
Runtime error |
175 ms |
262148 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
183 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
177 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1280 KB |
Output is correct |
2 |
Correct |
6 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1024 KB |
Output is correct |
4 |
Correct |
5 ms |
1024 KB |
Output is correct |
5 |
Correct |
12 ms |
1020 KB |
Output is correct |
6 |
Correct |
4 ms |
896 KB |
Output is correct |
7 |
Correct |
6 ms |
896 KB |
Output is correct |
8 |
Correct |
6 ms |
896 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
4 ms |
896 KB |
Output is correct |
11 |
Correct |
4 ms |
896 KB |
Output is correct |
12 |
Runtime error |
170 ms |
262148 KB |
Execution killed with signal 9 |
13 |
Halted |
0 ms |
0 KB |
- |