#include <vector>
#include <queue>
#include "train.h"
using namespace std;
int n, m;
vector<int> rgraph[5005];
int f[5005];
int freq[5005][5005];
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = (int)a.size();
m = (int)u.size();
for (int i = 0; i < m; i++) {
rgraph[v[i]].push_back(u[i]);
freq[u[i]][0]++;
}
queue<pair<int, int> > que;
for (int i = 0; i < n; i++) {
if (r[i]) {
f[i] = 1;
que.push(make_pair(i, 0));
}
}
while (!que.empty()) {
pair<int, int> pr = que.front();
//fprintf(stderr, "! %d %d\n", pr.first, pr.second);
int cur = pr.first; que.pop();
for (int idx = 0; idx < rgraph[cur].size(); idx++) {
int pre = rgraph[cur][idx];
if (f[pre] > n) continue;
if (a[pre]) {
int newf = f[cur] + r[pre];
if (newf > f[pre]) {
que.push(make_pair(pre, f[pre]));
f[pre] = newf;
}
} else {
freq[pre][pr.second]--;
freq[pre][f[cur]]++;
//fprintf(stderr, "freq %d -%d +%d => %d %d\n", pre, pr.second, f[cur], freq[pre][pr.second], freq[pre][f[cur]]);
int old_f = f[pre];
while (freq[pre][f[pre] - r[pre]] == 0) f[pre]++;
if (f[pre] > old_f) {
que.push(make_pair(pre, old_f));
}
}
}
}
vector<int> ans;
for (int i = 0; i < n; i++) {
//fprintf(stderr, "%d ", f[i]);
ans.push_back(f[i] > n ? 1 : 0);
}
return ans;
}
Compilation message
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:30:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int idx = 0; idx < rgraph[cur].size(); idx++) {
| ~~~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
392 ms |
36036 KB |
3rd lines differ - on the 96th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Incorrect |
1 ms |
460 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
21452 KB |
Output is correct |
2 |
Correct |
162 ms |
21436 KB |
Output is correct |
3 |
Correct |
193 ms |
21452 KB |
Output is correct |
4 |
Correct |
526 ms |
49440 KB |
Output is correct |
5 |
Correct |
625 ms |
45656 KB |
Output is correct |
6 |
Correct |
41 ms |
21444 KB |
Output is correct |
7 |
Correct |
61 ms |
24872 KB |
Output is correct |
8 |
Correct |
502 ms |
21412 KB |
Output is correct |
9 |
Correct |
18 ms |
21324 KB |
Output is correct |
10 |
Correct |
712 ms |
21436 KB |
Output is correct |
11 |
Correct |
605 ms |
21360 KB |
Output is correct |
12 |
Correct |
19 ms |
21316 KB |
Output is correct |
13 |
Correct |
1364 ms |
21432 KB |
Output is correct |
14 |
Correct |
1407 ms |
21424 KB |
Output is correct |
15 |
Correct |
1358 ms |
21416 KB |
Output is correct |
16 |
Correct |
1354 ms |
21444 KB |
Output is correct |
17 |
Correct |
1373 ms |
21424 KB |
Output is correct |
18 |
Correct |
125 ms |
21136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
21392 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1719 ms |
79924 KB |
Output is correct |
2 |
Correct |
1767 ms |
38044 KB |
Output is correct |
3 |
Execution timed out |
2092 ms |
67328 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
392 ms |
36036 KB |
3rd lines differ - on the 96th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |