#include <bits/stdc++.h>
using namespace std;
const int MX = 5042;
int n;
int mxScore[MX];
int deg[MX];
bool isAlice[MX];
bool isCharge[MX];
vector<int> rgraph[MX];
vector<int> graph[MX];
int chg(int a, int b, bool isMax) {
if (isMax)
return max(a, b);
return min(a, b);
}
void BFS(int layer) {
queue<int> nxt {};
for (int i = 0; i < n; i++) {
deg[i] = 0;
if (isCharge[i] && mxScore[i] >= layer)
nxt.push(layer);
}
for (int i = 0; i < n; i++)
for (auto& x: rgraph[i])
deg[x]++;
while (!nxt.empty()) {
auto cur = nxt.front();
nxt.pop();
if (deg[cur] == 0) {
for (auto& x: graph[cur])
mxScore[cur] = chg(mxScore[cur], mxScore[x], isAlice[cur]);
mxScore[cur] += isCharge[cur];
}
for (auto& x: rgraph[cur])
if (--deg[x] == 0)
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[u[i]].push_back(v[i]);
graph[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] = mxScore[i] >= (int)r.size() + 1;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
321 ms |
980 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
468 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
498 ms |
1436 KB |
Output is correct |
2 |
Correct |
521 ms |
1424 KB |
Output is correct |
3 |
Correct |
469 ms |
1484 KB |
Output is correct |
4 |
Incorrect |
521 ms |
1372 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
404 ms |
1360 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
488 ms |
1364 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
321 ms |
980 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |