#include "train.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef int ll;
#define MAX 6000
vector<ll> A, s;
ll N, M;
vector<ll> adj[MAX], rev[MAX], deg, d;
ll mp[MAX][MAX];
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
ll i;
A = a;
N = a.size();
M = u.size();
d.resize(N);
deg.resize(N);
vector<ll> res;
res.resize(N);
for (i = 0; i < N; i++) if (r[i]) s.push_back(i);
for (i = 0; i < M; i++) adj[u[i]].push_back(v[i]), rev[v[i]].push_back(u[i]), d[u[i]]++;
for (auto st : s) {
deg = d;
queue<ll> q;
vector<ll> vis;
vis = res;
q.push(st);
vis[st] = 1;
while (!q.empty()) {
ll t = q.front();
q.pop();
for (auto x : rev[t]) {
if (x == -1) continue;
if (mp[t][x]) continue;
if (vis[x]) continue;
deg[x]--;
if (a[x]) q.push(x), vis[x] = 1;
else if (deg[x] == 0) q.push(x), vis[x] = 1;
}
}
bool c = true;
if (!a[st]) {
for (auto asdf : adj[st]) {
if (!vis[asdf]) {
c = 0;
break;
}
}
}
else {
c = 0;
for (auto asdf : adj[st]) {
if (vis[asdf]) {
c = 1;
break;
}
}
}
if (c) {
for (i = 0; i < N; i++) res[i] |= vis[i];
for (i = 0; i < adj[st].size(); i++) {
if (vis[adj[st][i]]) mp[st][adj[st][i]] = mp[adj[st][i]][st] = 1;
}
}
else {
for (i = 0; i < adj[st].size(); i++) if (vis[adj[st][i]]) adj[st][i] = 0;
}
}
return res;
}
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:69:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (i = 0; i < adj[st].size(); i++) {
| ~~^~~~~~~~~~~~~~~~
train.cpp:74:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for (i = 0; i < adj[st].size(); i++) if (vis[adj[st][i]]) adj[st][i] = 0;
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
3276 KB |
3rd lines differ - on the 26th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
588 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
1988 KB |
Output is correct |
2 |
Correct |
148 ms |
1960 KB |
Output is correct |
3 |
Correct |
178 ms |
1868 KB |
Output is correct |
4 |
Correct |
55 ms |
28984 KB |
Output is correct |
5 |
Correct |
24 ms |
5196 KB |
Output is correct |
6 |
Correct |
23 ms |
1980 KB |
Output is correct |
7 |
Correct |
91 ms |
50228 KB |
Output is correct |
8 |
Correct |
13 ms |
1868 KB |
Output is correct |
9 |
Correct |
12 ms |
1720 KB |
Output is correct |
10 |
Correct |
14 ms |
2412 KB |
Output is correct |
11 |
Correct |
11 ms |
1868 KB |
Output is correct |
12 |
Correct |
8 ms |
1612 KB |
Output is correct |
13 |
Correct |
18 ms |
1868 KB |
Output is correct |
14 |
Correct |
18 ms |
1956 KB |
Output is correct |
15 |
Correct |
17 ms |
1880 KB |
Output is correct |
16 |
Correct |
17 ms |
1968 KB |
Output is correct |
17 |
Correct |
17 ms |
1952 KB |
Output is correct |
18 |
Correct |
248 ms |
1576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
1740 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1864 KB |
Output is correct |
2 |
Correct |
17 ms |
1876 KB |
Output is correct |
3 |
Correct |
16 ms |
1956 KB |
Output is correct |
4 |
Correct |
16 ms |
1740 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
5 ms |
1100 KB |
Output is correct |
7 |
Correct |
6 ms |
1312 KB |
Output is correct |
8 |
Correct |
6 ms |
1360 KB |
Output is correct |
9 |
Correct |
6 ms |
1236 KB |
Output is correct |
10 |
Correct |
3 ms |
972 KB |
Output is correct |
11 |
Correct |
6 ms |
1356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
3276 KB |
3rd lines differ - on the 26th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |