#include "train.h"
#include <bits/stdc++.h>
using namespace std;
using idata = vector<int>;
using bdata = vector<bool>;
using igrid = vector<idata>;
idata controller, charger;
int N, M;
igrid roads;
idata visited; int stage = 1;
idata depth;
bdata status;
pair<int, bool> dfs (int node, int _depth) {
if (visited[node] == stage) return { depth[node], status[node] };
depth [node] = _depth;
status [node] = false;
visited[node] = stage;
int gdepth = controller[node] == 1 ? 1e9 : -1;
bool rstatus = controller[node] == 0;
for (int next : roads[node]) {
pair<int, bool> ldata = dfs(next, _depth + 1);
if (charger[node] && ldata.first <= depth[node]) ldata.second = true;
if (controller[node] == 1) {
gdepth = min(gdepth, ldata.first);
rstatus |= ldata.second;
} else {
gdepth = max(gdepth, ldata.first);
rstatus &= ldata.second;
}
}
status[node] = rstatus;
return { gdepth, rstatus };
}
idata who_wins(idata _controller, idata _charger, idata u, idata v) {
N = _controller.size(); M = u.size();
controller = _controller;
charger = _charger;
roads.resize(N);
for (int i = 0; i < M; i ++)
roads[u[i]].push_back(v[i]);
visited.resize(N);
depth .resize(N);
status.resize(N);
idata answer(N, false);
for (int i = 0; i < N; i ++) {
answer[i] = dfs(i, 0).second;
stage ++;
}
return answer;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
316 ms |
1364 KB |
Output is correct |
2 |
Correct |
77 ms |
1108 KB |
Output is correct |
3 |
Correct |
32 ms |
980 KB |
Output is correct |
4 |
Correct |
12 ms |
912 KB |
Output is correct |
5 |
Correct |
6 ms |
852 KB |
Output is correct |
6 |
Correct |
5 ms |
852 KB |
Output is correct |
7 |
Correct |
4 ms |
852 KB |
Output is correct |
8 |
Correct |
3 ms |
852 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
1620 KB |
Output is correct |
2 |
Correct |
200 ms |
1568 KB |
Output is correct |
3 |
Correct |
215 ms |
1492 KB |
Output is correct |
4 |
Correct |
1281 ms |
1408 KB |
Output is correct |
5 |
Incorrect |
916 ms |
1336 KB |
3rd lines differ - on the 11th token, expected: '0', found: '1' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
914 ms |
1212 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1294 ms |
1364 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
316 ms |
1364 KB |
Output is correct |
2 |
Correct |
77 ms |
1108 KB |
Output is correct |
3 |
Correct |
32 ms |
980 KB |
Output is correct |
4 |
Correct |
12 ms |
912 KB |
Output is correct |
5 |
Correct |
6 ms |
852 KB |
Output is correct |
6 |
Correct |
5 ms |
852 KB |
Output is correct |
7 |
Correct |
4 ms |
852 KB |
Output is correct |
8 |
Correct |
3 ms |
852 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
13 |
Halted |
0 ms |
0 KB |
- |