#include "train.h"
#include <bits/stdc++.h>
using namespace std;
const int AREZOU = 1;
const int BORZOU = 0;
const int CHARGING_STATION = 1;
const int CHARGING_SET = 1;
const int NON_CHARGING_SET = 0;
const int VISITED = 1;
const int UNVISITED = 0;
int N, M;
vector<int> station, owner;
vector<vector<int>> G, G_inverse;
vector<int> in_degree;
vector<int> visited;
vector<int> charging_set;
vector<int> new_charging_set;
void initialize_charging_set() {
visited.assign(N, UNVISITED);
in_degree.assign(N, 0);
charging_set.assign(N, NON_CHARGING_SET);
queue<int> q;
for (int i = 0; i < N; i++)
if (station[i] == CHARGING_STATION && new_charging_set[i] == CHARGING_SET)
q.push(i), visited[i] = VISITED;
while (!q.empty()) {
int u = q.front(); q.pop();
charging_set[u] = CHARGING_SET;
for (auto v : G_inverse[u]) {
if (visited[v] == VISITED) continue;
switch (owner[v]) {
case AREZOU:
if (visited[v] == UNVISITED) {
visited[v] = VISITED;
q.push(v);
}
break;
case BORZOU:
in_degree[v]++;
if (in_degree[v] == G[v].size() && visited[v] == UNVISITED) {
visited[v] = VISITED;
q.push(v);
}
break;
}
}
}
}
vector<int> who_wins(vector<int> owner_, vector<int> charge_, vector<int> u_, vector<int> v_) {
owner = owner_, station = charge_;
N = owner.size(), M = u_.size();
G.resize(N), G_inverse.resize(N);
new_charging_set.resize(N, CHARGING_SET);
for (int i = 0; i < M; i++) {
G[u_[i]].push_back(v_[i]);
G_inverse[v_[i]].push_back(u_[i]);
}
while (charging_set != new_charging_set) {
initialize_charging_set();
for (int i = 0; i < N; i++) {
switch (owner[i]) {
case AREZOU:
new_charging_set[i] = NON_CHARGING_SET;
for (auto v : G[i])
if (charging_set[v] == CHARGING_SET)
new_charging_set[i] = CHARGING_SET;
break;
case BORZOU:
new_charging_set[i] = CHARGING_SET;
for (auto v : G[i])
if (charging_set[v] == NON_CHARGING_SET)
new_charging_set[i] = NON_CHARGING_SET;
break;
}
}
}
vector<int> res(N);
for (int i = 0; i < N; i++) res[i] = (charging_set[i] == CHARGING_SET);
return res;
}
Compilation message
train.cpp: In function 'void initialize_charging_set()':
train.cpp:50:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (in_degree[v] == G[v].size() && visited[v] == UNVISITED) {
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1272 KB |
Output is correct |
2 |
Correct |
11 ms |
1272 KB |
Output is correct |
3 |
Correct |
11 ms |
1272 KB |
Output is correct |
4 |
Correct |
12 ms |
1272 KB |
Output is correct |
5 |
Correct |
11 ms |
1272 KB |
Output is correct |
6 |
Correct |
11 ms |
1272 KB |
Output is correct |
7 |
Correct |
13 ms |
1272 KB |
Output is correct |
8 |
Correct |
10 ms |
1272 KB |
Output is correct |
9 |
Correct |
9 ms |
1272 KB |
Output is correct |
10 |
Correct |
8 ms |
1272 KB |
Output is correct |
11 |
Correct |
6 ms |
1244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
252 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
372 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
1528 KB |
Output is correct |
2 |
Correct |
218 ms |
1500 KB |
Output is correct |
3 |
Correct |
319 ms |
1528 KB |
Output is correct |
4 |
Correct |
13 ms |
1528 KB |
Output is correct |
5 |
Correct |
19 ms |
1528 KB |
Output is correct |
6 |
Correct |
16 ms |
1528 KB |
Output is correct |
7 |
Correct |
12 ms |
1528 KB |
Output is correct |
8 |
Correct |
12 ms |
1528 KB |
Output is correct |
9 |
Correct |
10 ms |
1400 KB |
Output is correct |
10 |
Correct |
11 ms |
1528 KB |
Output is correct |
11 |
Correct |
11 ms |
1528 KB |
Output is correct |
12 |
Correct |
11 ms |
1400 KB |
Output is correct |
13 |
Correct |
12 ms |
1528 KB |
Output is correct |
14 |
Correct |
12 ms |
1528 KB |
Output is correct |
15 |
Correct |
12 ms |
1528 KB |
Output is correct |
16 |
Correct |
12 ms |
1532 KB |
Output is correct |
17 |
Correct |
12 ms |
1528 KB |
Output is correct |
18 |
Correct |
438 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1400 KB |
Output is correct |
2 |
Correct |
12 ms |
1656 KB |
Output is correct |
3 |
Correct |
13 ms |
1656 KB |
Output is correct |
4 |
Correct |
14 ms |
1656 KB |
Output is correct |
5 |
Correct |
13 ms |
1656 KB |
Output is correct |
6 |
Correct |
13 ms |
1660 KB |
Output is correct |
7 |
Correct |
13 ms |
1656 KB |
Output is correct |
8 |
Correct |
13 ms |
1656 KB |
Output is correct |
9 |
Correct |
13 ms |
1656 KB |
Output is correct |
10 |
Correct |
12 ms |
1660 KB |
Output is correct |
11 |
Correct |
12 ms |
1788 KB |
Output is correct |
12 |
Correct |
12 ms |
1656 KB |
Output is correct |
13 |
Correct |
12 ms |
1784 KB |
Output is correct |
14 |
Correct |
12 ms |
1656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1572 KB |
Output is correct |
2 |
Correct |
12 ms |
1504 KB |
Output is correct |
3 |
Correct |
13 ms |
1460 KB |
Output is correct |
4 |
Correct |
11 ms |
1400 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
7 ms |
1144 KB |
Output is correct |
7 |
Correct |
7 ms |
888 KB |
Output is correct |
8 |
Correct |
8 ms |
888 KB |
Output is correct |
9 |
Correct |
8 ms |
1016 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
7 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1272 KB |
Output is correct |
2 |
Correct |
11 ms |
1272 KB |
Output is correct |
3 |
Correct |
11 ms |
1272 KB |
Output is correct |
4 |
Correct |
12 ms |
1272 KB |
Output is correct |
5 |
Correct |
11 ms |
1272 KB |
Output is correct |
6 |
Correct |
11 ms |
1272 KB |
Output is correct |
7 |
Correct |
13 ms |
1272 KB |
Output is correct |
8 |
Correct |
10 ms |
1272 KB |
Output is correct |
9 |
Correct |
9 ms |
1272 KB |
Output is correct |
10 |
Correct |
8 ms |
1272 KB |
Output is correct |
11 |
Correct |
6 ms |
1244 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
252 KB |
Output is correct |
22 |
Correct |
2 ms |
256 KB |
Output is correct |
23 |
Correct |
2 ms |
256 KB |
Output is correct |
24 |
Correct |
2 ms |
256 KB |
Output is correct |
25 |
Correct |
2 ms |
372 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
2 ms |
256 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
109 ms |
1528 KB |
Output is correct |
33 |
Correct |
218 ms |
1500 KB |
Output is correct |
34 |
Correct |
319 ms |
1528 KB |
Output is correct |
35 |
Correct |
13 ms |
1528 KB |
Output is correct |
36 |
Correct |
19 ms |
1528 KB |
Output is correct |
37 |
Correct |
16 ms |
1528 KB |
Output is correct |
38 |
Correct |
12 ms |
1528 KB |
Output is correct |
39 |
Correct |
12 ms |
1528 KB |
Output is correct |
40 |
Correct |
10 ms |
1400 KB |
Output is correct |
41 |
Correct |
11 ms |
1528 KB |
Output is correct |
42 |
Correct |
11 ms |
1528 KB |
Output is correct |
43 |
Correct |
11 ms |
1400 KB |
Output is correct |
44 |
Correct |
12 ms |
1528 KB |
Output is correct |
45 |
Correct |
12 ms |
1528 KB |
Output is correct |
46 |
Correct |
12 ms |
1528 KB |
Output is correct |
47 |
Correct |
12 ms |
1532 KB |
Output is correct |
48 |
Correct |
12 ms |
1528 KB |
Output is correct |
49 |
Correct |
438 ms |
1272 KB |
Output is correct |
50 |
Correct |
10 ms |
1400 KB |
Output is correct |
51 |
Correct |
12 ms |
1656 KB |
Output is correct |
52 |
Correct |
13 ms |
1656 KB |
Output is correct |
53 |
Correct |
14 ms |
1656 KB |
Output is correct |
54 |
Correct |
13 ms |
1656 KB |
Output is correct |
55 |
Correct |
13 ms |
1660 KB |
Output is correct |
56 |
Correct |
13 ms |
1656 KB |
Output is correct |
57 |
Correct |
13 ms |
1656 KB |
Output is correct |
58 |
Correct |
13 ms |
1656 KB |
Output is correct |
59 |
Correct |
12 ms |
1660 KB |
Output is correct |
60 |
Correct |
12 ms |
1788 KB |
Output is correct |
61 |
Correct |
12 ms |
1656 KB |
Output is correct |
62 |
Correct |
12 ms |
1784 KB |
Output is correct |
63 |
Correct |
12 ms |
1656 KB |
Output is correct |
64 |
Correct |
13 ms |
1572 KB |
Output is correct |
65 |
Correct |
12 ms |
1504 KB |
Output is correct |
66 |
Correct |
13 ms |
1460 KB |
Output is correct |
67 |
Correct |
11 ms |
1400 KB |
Output is correct |
68 |
Correct |
4 ms |
376 KB |
Output is correct |
69 |
Correct |
7 ms |
1144 KB |
Output is correct |
70 |
Correct |
7 ms |
888 KB |
Output is correct |
71 |
Correct |
8 ms |
888 KB |
Output is correct |
72 |
Correct |
8 ms |
1016 KB |
Output is correct |
73 |
Correct |
3 ms |
504 KB |
Output is correct |
74 |
Correct |
7 ms |
860 KB |
Output is correct |
75 |
Correct |
184 ms |
1756 KB |
Output is correct |
76 |
Correct |
289 ms |
1912 KB |
Output is correct |
77 |
Correct |
402 ms |
1788 KB |
Output is correct |
78 |
Correct |
397 ms |
1808 KB |
Output is correct |
79 |
Correct |
402 ms |
1784 KB |
Output is correct |
80 |
Correct |
13 ms |
1660 KB |
Output is correct |
81 |
Correct |
15 ms |
1784 KB |
Output is correct |
82 |
Correct |
15 ms |
1784 KB |
Output is correct |
83 |
Correct |
17 ms |
1780 KB |
Output is correct |
84 |
Correct |
18 ms |
1784 KB |
Output is correct |
85 |
Correct |
15 ms |
1784 KB |
Output is correct |
86 |
Correct |
19 ms |
1784 KB |
Output is correct |
87 |
Correct |
13 ms |
1784 KB |
Output is correct |
88 |
Correct |
26 ms |
1656 KB |
Output is correct |
89 |
Correct |
15 ms |
1784 KB |
Output is correct |
90 |
Correct |
37 ms |
1784 KB |
Output is correct |
91 |
Correct |
39 ms |
1784 KB |
Output is correct |
92 |
Correct |
62 ms |
1784 KB |
Output is correct |
93 |
Correct |
61 ms |
1784 KB |
Output is correct |
94 |
Correct |
62 ms |
1772 KB |
Output is correct |
95 |
Correct |
68 ms |
1784 KB |
Output is correct |
96 |
Correct |
142 ms |
1672 KB |
Output is correct |
97 |
Correct |
520 ms |
1744 KB |
Output is correct |
98 |
Correct |
838 ms |
1784 KB |
Output is correct |
99 |
Correct |
877 ms |
1788 KB |
Output is correct |
100 |
Correct |
442 ms |
1528 KB |
Output is correct |