#include <bits/stdc++.h>
using namespace std;
const int MX = 5042;
int n;
int deg[MX];
bool vis[MX];
bool isOk[MX];
bool isAlice[MX];
bool isCharge[MX];
vector<int> rgraph[MX];
void BFS(int layer) {
queue<int> nxt {};
for (int i = 0; i < n; i++) {
deg[i] = 0;
if (isCharge[i] && vis[i])
nxt.push(layer);
}
for (int i = 0; i < n; i++) {
vis[i] = isOk[i] = false;
for (auto& x: rgraph[i])
deg[x]++;
}
while (!nxt.empty()) {
auto cur = nxt.front();
//cout << "cur is " << cur << '\n';
nxt.pop();
if (vis[cur])
continue;
vis[cur] = true;
for (auto& x: rgraph[cur]) {
if (!vis[x] && (--deg[x] == 0 || isAlice[x])) {
isOk[x] = true;
nxt.push(x);
}
}
}
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = (int)a.size();
for (int i = 0; i < (int)u.size(); i++)
rgraph[v[i]].push_back(u[i]);
for (int i = 0; i < n; i++) {
isAlice[i] = a[i];
isCharge[i] = r[i];
}
for (int layer = 0; layer <= (int)r.size(); layer++)
BFS(layer);
vector<int> ans (n);
for (int i = 0; i < n; i++)
ans[i] = isOk[i];
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
323 ms |
844 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
460 ms |
1068 KB |
Output is correct |
2 |
Correct |
467 ms |
1064 KB |
Output is correct |
3 |
Correct |
494 ms |
1056 KB |
Output is correct |
4 |
Incorrect |
469 ms |
980 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
405 ms |
920 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
423 ms |
1048 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
323 ms |
844 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |