#include "train.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uset = unordered_set<int>;
const int nmax = 5e3 + 5;
vector<int> g[nmax], t[nmax];
vector<int> own, charge, rez, degree;
int n, m;
int cnt = 0;
void solve(uset& V) {
if(V.size() == 0)
return;
uset S;
for(auto x : V) {
if(charge[x])
S.insert(x);
for(int i = 0; i < g[x].size(); i++) {
if(V.count(g[x][i]) == 0)
swap(g[x][i], g[x].back()), g[x].pop_back(), i--;
}
for(int i = 0; i < t[x].size(); i++) {
if(V.count(t[x][i]) == 0)
swap(t[x][i], t[x].back()), t[x].pop_back(), i--;
}
}
if(S.size() == 0) {
for(auto x : V)
rez[x] = 0;
return;
}
for(auto x : V) {
if(charge[x])
degree[x] = 0;
if(own[x] == 1)
degree[x] = 1;
else
degree[x] = g[x].size();
}
queue<int> que;
function<void()> markall = [&]() {
while (!que.empty()) {
int node = que.front();
for(auto x : t[node]) {
degree[x]--;
if(degree[x] == 0 && !S.count(x))
S.insert(x),
que.push(x);
}
que.pop();
}
que = queue<int>();
return;
};
for(auto x : S)
que.push(x);
markall();
if(S.size() == V.size()) {
for(auto x : V)
rez[x] = 1;
return;
}
uset notS;
for(auto x : V)
if(S.count(x) == 0)
notS.insert(x);
for(auto x : V) {
if(notS.count(x) == 1)
degree[x] = 0;
if(own[x] == 0)
degree[x] = 1;
else
degree[x] = g[x].size();
}
swap(S, notS);
for(auto x : S)
que.push(x);
markall();
for(auto x : S)
rez[x] = 0, // formality
V.erase(x);
solve(V);
}
std::vector<int> who_wins(std::vector<int> A, std::vector<int> R, std::vector<int> U, std::vector<int> V) {
own = move(A);
charge = move(R);
n = own.size();
m = U.size();
degree.resize(n, 0);
rez.resize(n, 0);
for(int i = 0; i < m; i++)
g[U[i]].push_back(V[i]),
t[V[i]].push_back(U[i]);
uset Vertex;
for(int i = 0; i < n; i++)
Vertex.insert(i);
solve(Vertex);
return rez;
}
Compilation message
train.cpp: In function 'void solve(uset&)':
train.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int i = 0; i < g[x].size(); i++) {
| ~~^~~~~~~~~~~~~
train.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = 0; i < t[x].size(); i++) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1876 KB |
Output is correct |
2 |
Correct |
11 ms |
2412 KB |
Output is correct |
3 |
Correct |
10 ms |
2132 KB |
Output is correct |
4 |
Correct |
9 ms |
2036 KB |
Output is correct |
5 |
Correct |
11 ms |
1876 KB |
Output is correct |
6 |
Correct |
9 ms |
1876 KB |
Output is correct |
7 |
Correct |
7 ms |
1492 KB |
Output is correct |
8 |
Correct |
11 ms |
2260 KB |
Output is correct |
9 |
Correct |
12 ms |
1748 KB |
Output is correct |
10 |
Correct |
8 ms |
1620 KB |
Output is correct |
11 |
Correct |
7 ms |
1452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
544 KB |
Output is correct |
20 |
Correct |
1 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
661 ms |
88648 KB |
Output is correct |
2 |
Correct |
1279 ms |
149684 KB |
Output is correct |
3 |
Correct |
1474 ms |
177084 KB |
Output is correct |
4 |
Correct |
14 ms |
1876 KB |
Output is correct |
5 |
Correct |
13 ms |
2132 KB |
Output is correct |
6 |
Correct |
14 ms |
2160 KB |
Output is correct |
7 |
Correct |
10 ms |
1964 KB |
Output is correct |
8 |
Correct |
11 ms |
1960 KB |
Output is correct |
9 |
Correct |
9 ms |
1876 KB |
Output is correct |
10 |
Correct |
11 ms |
2004 KB |
Output is correct |
11 |
Correct |
10 ms |
2004 KB |
Output is correct |
12 |
Correct |
13 ms |
1844 KB |
Output is correct |
13 |
Correct |
10 ms |
1876 KB |
Output is correct |
14 |
Correct |
14 ms |
1836 KB |
Output is correct |
15 |
Correct |
10 ms |
1844 KB |
Output is correct |
16 |
Correct |
10 ms |
1876 KB |
Output is correct |
17 |
Correct |
12 ms |
1876 KB |
Output is correct |
18 |
Runtime error |
1399 ms |
262144 KB |
Execution killed with signal 9 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1748 KB |
Output is correct |
2 |
Correct |
13 ms |
1748 KB |
Output is correct |
3 |
Correct |
10 ms |
1748 KB |
Output is correct |
4 |
Correct |
12 ms |
1876 KB |
Output is correct |
5 |
Correct |
14 ms |
1752 KB |
Output is correct |
6 |
Correct |
10 ms |
1876 KB |
Output is correct |
7 |
Correct |
10 ms |
1756 KB |
Output is correct |
8 |
Correct |
12 ms |
1748 KB |
Output is correct |
9 |
Correct |
10 ms |
1876 KB |
Output is correct |
10 |
Correct |
9 ms |
1624 KB |
Output is correct |
11 |
Correct |
9 ms |
1748 KB |
Output is correct |
12 |
Correct |
10 ms |
1628 KB |
Output is correct |
13 |
Correct |
11 ms |
1792 KB |
Output is correct |
14 |
Correct |
13 ms |
1732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1796 KB |
Output is correct |
2 |
Correct |
10 ms |
1620 KB |
Output is correct |
3 |
Correct |
14 ms |
1848 KB |
Output is correct |
4 |
Correct |
8 ms |
1620 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
5 ms |
1352 KB |
Output is correct |
7 |
Correct |
6 ms |
1108 KB |
Output is correct |
8 |
Correct |
6 ms |
1108 KB |
Output is correct |
9 |
Correct |
6 ms |
1128 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
6 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1876 KB |
Output is correct |
2 |
Correct |
11 ms |
2412 KB |
Output is correct |
3 |
Correct |
10 ms |
2132 KB |
Output is correct |
4 |
Correct |
9 ms |
2036 KB |
Output is correct |
5 |
Correct |
11 ms |
1876 KB |
Output is correct |
6 |
Correct |
9 ms |
1876 KB |
Output is correct |
7 |
Correct |
7 ms |
1492 KB |
Output is correct |
8 |
Correct |
11 ms |
2260 KB |
Output is correct |
9 |
Correct |
12 ms |
1748 KB |
Output is correct |
10 |
Correct |
8 ms |
1620 KB |
Output is correct |
11 |
Correct |
7 ms |
1452 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
544 KB |
Output is correct |
31 |
Correct |
1 ms |
488 KB |
Output is correct |
32 |
Correct |
661 ms |
88648 KB |
Output is correct |
33 |
Correct |
1279 ms |
149684 KB |
Output is correct |
34 |
Correct |
1474 ms |
177084 KB |
Output is correct |
35 |
Correct |
14 ms |
1876 KB |
Output is correct |
36 |
Correct |
13 ms |
2132 KB |
Output is correct |
37 |
Correct |
14 ms |
2160 KB |
Output is correct |
38 |
Correct |
10 ms |
1964 KB |
Output is correct |
39 |
Correct |
11 ms |
1960 KB |
Output is correct |
40 |
Correct |
9 ms |
1876 KB |
Output is correct |
41 |
Correct |
11 ms |
2004 KB |
Output is correct |
42 |
Correct |
10 ms |
2004 KB |
Output is correct |
43 |
Correct |
13 ms |
1844 KB |
Output is correct |
44 |
Correct |
10 ms |
1876 KB |
Output is correct |
45 |
Correct |
14 ms |
1836 KB |
Output is correct |
46 |
Correct |
10 ms |
1844 KB |
Output is correct |
47 |
Correct |
10 ms |
1876 KB |
Output is correct |
48 |
Correct |
12 ms |
1876 KB |
Output is correct |
49 |
Runtime error |
1399 ms |
262144 KB |
Execution killed with signal 9 |
50 |
Halted |
0 ms |
0 KB |
- |