#include "train.h"
#include <algorithm>
#include <vector>
#include <unordered_set>
#include <queue>
using namespace std;
const int N = 5006;
int n, m;
vector<int> g[N],ing[N];
bool col[N],chrg[N];
void rev(vector<bool> &s, vector<bool> &ans){
for (int i = 0; i < n; i++){
if (s[i] == 0) ans[i]=1;
}
}
void fa(vector<bool> &s, vector<bool> &ans){
queue<int> q;
for (int i = 0; i < s.size(); i++){
if (s[i]){
q.push(i);
ans[i] = 1;
}
}
while (!q.empty()){
int v = q.front();
q.pop();
for (auto to : ing[v]){
if (ans[to]) continue;
bool mb = true;
for (auto k : g[to]){
mb &= ans[k] == 1;
}
if (col[to] || mb){
ans[to]=1;
q.push(to);
}
}
}
}
void fb(vector<bool> &s, vector<bool> &ans){
queue<int> q;
for (int i = 0; i < s.size();i++){
if (s[i]){
q.push(i);
ans[i] = 1;
}
}
while (!q.empty()){
int v = q.front();
q.pop();
for (auto to : ing[v]){
if (ans[to]) continue;
bool mb = true;
for (auto k : g[to]){
mb &= ans[k] == 1;
}
if (!col[to] || mb){
ans[to] = 1;
q.push(to);
}
}
}
}
void intersect(vector<bool> &a, vector<bool> &b, vector<bool> &ans){
for (int i = 0; i < a.size();i++){
if (b[i] && a[i]) ans[i]=1;
}
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = a.size();
m = u.size();
for (int i = 0; i < m; i++){
g[u[i]].push_back(v[i]);
ing[v[i]].push_back(u[i]);
}
for (int i = 0; i < n; i++){
if (a[i]){
col[i] = true;
}
}
for (int i = 0; i < n; i++){
if (r[i]) chrg[i] = true;
}
while (1){
vector<bool> R(n);
for (int i = 0; i < n; i++){
if (chrg[i]) R[i]=1;
}
vector<bool> far(n), gg(n) , x(n), ht(n);
fa(R, far);
rev(far, gg);
fb(gg, x);
intersect(far, x, ht);
bool mb = false;
for (int i = 0; i < ht.size();i++){
if (ht[i] && chrg[i]) mb = true, chrg[i] = false;
}
if (!mb){
vector<int> ans(n,1);
for (int i = 0; i < x.size();i++){
if (x[i])
ans[i] = 0;
}
return ans;
}
}
}
/*
2 4
0 1
1 0
0 0
0 1
1 0
1 1
*/
Compilation message
train.cpp: In function 'void fa(std::vector<bool>&, std::vector<bool>&)':
train.cpp:22:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size(); i++){
~~^~~~~~~~~~
train.cpp: In function 'void fb(std::vector<bool>&, std::vector<bool>&)':
train.cpp:47:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size();i++){
~~^~~~~~~~~~
train.cpp: In function 'void intersect(std::vector<bool>&, std::vector<bool>&, std::vector<bool>&)':
train.cpp:71:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a.size();i++){
~~^~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:103:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ht.size();i++){
~~^~~~~~~~~~~
train.cpp:108:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < x.size();i++){
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1016 KB |
Output is correct |
2 |
Correct |
9 ms |
1128 KB |
Output is correct |
3 |
Correct |
13 ms |
1196 KB |
Output is correct |
4 |
Correct |
8 ms |
1228 KB |
Output is correct |
5 |
Correct |
7 ms |
1284 KB |
Output is correct |
6 |
Correct |
7 ms |
1284 KB |
Output is correct |
7 |
Correct |
7 ms |
1284 KB |
Output is correct |
8 |
Correct |
8 ms |
1296 KB |
Output is correct |
9 |
Correct |
7 ms |
1296 KB |
Output is correct |
10 |
Correct |
11 ms |
1296 KB |
Output is correct |
11 |
Correct |
6 ms |
1296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1296 KB |
Output is correct |
2 |
Correct |
2 ms |
1296 KB |
Output is correct |
3 |
Correct |
2 ms |
1296 KB |
Output is correct |
4 |
Correct |
2 ms |
1296 KB |
Output is correct |
5 |
Correct |
2 ms |
1296 KB |
Output is correct |
6 |
Correct |
2 ms |
1296 KB |
Output is correct |
7 |
Correct |
2 ms |
1296 KB |
Output is correct |
8 |
Correct |
2 ms |
1296 KB |
Output is correct |
9 |
Correct |
2 ms |
1296 KB |
Output is correct |
10 |
Correct |
2 ms |
1296 KB |
Output is correct |
11 |
Correct |
2 ms |
1296 KB |
Output is correct |
12 |
Correct |
2 ms |
1296 KB |
Output is correct |
13 |
Correct |
2 ms |
1296 KB |
Output is correct |
14 |
Correct |
2 ms |
1296 KB |
Output is correct |
15 |
Correct |
2 ms |
1296 KB |
Output is correct |
16 |
Correct |
2 ms |
1296 KB |
Output is correct |
17 |
Correct |
2 ms |
1296 KB |
Output is correct |
18 |
Correct |
2 ms |
1296 KB |
Output is correct |
19 |
Correct |
2 ms |
1296 KB |
Output is correct |
20 |
Correct |
2 ms |
1296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
137 ms |
1712 KB |
Output is correct |
2 |
Correct |
292 ms |
1768 KB |
Output is correct |
3 |
Correct |
431 ms |
1768 KB |
Output is correct |
4 |
Correct |
12 ms |
1768 KB |
Output is correct |
5 |
Correct |
15 ms |
1768 KB |
Output is correct |
6 |
Correct |
14 ms |
1768 KB |
Output is correct |
7 |
Correct |
11 ms |
1768 KB |
Output is correct |
8 |
Correct |
13 ms |
1768 KB |
Output is correct |
9 |
Correct |
11 ms |
1768 KB |
Output is correct |
10 |
Correct |
11 ms |
1768 KB |
Output is correct |
11 |
Correct |
11 ms |
1768 KB |
Output is correct |
12 |
Correct |
10 ms |
1768 KB |
Output is correct |
13 |
Correct |
12 ms |
1768 KB |
Output is correct |
14 |
Correct |
12 ms |
1768 KB |
Output is correct |
15 |
Correct |
18 ms |
1768 KB |
Output is correct |
16 |
Correct |
13 ms |
1768 KB |
Output is correct |
17 |
Correct |
12 ms |
1768 KB |
Output is correct |
18 |
Correct |
665 ms |
1768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1768 KB |
Output is correct |
2 |
Correct |
12 ms |
1768 KB |
Output is correct |
3 |
Correct |
12 ms |
1768 KB |
Output is correct |
4 |
Correct |
12 ms |
1768 KB |
Output is correct |
5 |
Correct |
13 ms |
1768 KB |
Output is correct |
6 |
Correct |
13 ms |
1768 KB |
Output is correct |
7 |
Correct |
14 ms |
1768 KB |
Output is correct |
8 |
Correct |
21 ms |
1768 KB |
Output is correct |
9 |
Correct |
11 ms |
1768 KB |
Output is correct |
10 |
Correct |
12 ms |
1768 KB |
Output is correct |
11 |
Correct |
11 ms |
1768 KB |
Output is correct |
12 |
Correct |
11 ms |
1768 KB |
Output is correct |
13 |
Correct |
12 ms |
1768 KB |
Output is correct |
14 |
Correct |
12 ms |
1768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1768 KB |
Output is correct |
2 |
Correct |
21 ms |
1768 KB |
Output is correct |
3 |
Correct |
13 ms |
1768 KB |
Output is correct |
4 |
Correct |
12 ms |
1768 KB |
Output is correct |
5 |
Correct |
2 ms |
1768 KB |
Output is correct |
6 |
Correct |
7 ms |
1768 KB |
Output is correct |
7 |
Correct |
8 ms |
1768 KB |
Output is correct |
8 |
Correct |
9 ms |
1768 KB |
Output is correct |
9 |
Correct |
9 ms |
1768 KB |
Output is correct |
10 |
Correct |
4 ms |
1768 KB |
Output is correct |
11 |
Correct |
8 ms |
1768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1016 KB |
Output is correct |
2 |
Correct |
9 ms |
1128 KB |
Output is correct |
3 |
Correct |
13 ms |
1196 KB |
Output is correct |
4 |
Correct |
8 ms |
1228 KB |
Output is correct |
5 |
Correct |
7 ms |
1284 KB |
Output is correct |
6 |
Correct |
7 ms |
1284 KB |
Output is correct |
7 |
Correct |
7 ms |
1284 KB |
Output is correct |
8 |
Correct |
8 ms |
1296 KB |
Output is correct |
9 |
Correct |
7 ms |
1296 KB |
Output is correct |
10 |
Correct |
11 ms |
1296 KB |
Output is correct |
11 |
Correct |
6 ms |
1296 KB |
Output is correct |
12 |
Correct |
2 ms |
1296 KB |
Output is correct |
13 |
Correct |
2 ms |
1296 KB |
Output is correct |
14 |
Correct |
2 ms |
1296 KB |
Output is correct |
15 |
Correct |
2 ms |
1296 KB |
Output is correct |
16 |
Correct |
2 ms |
1296 KB |
Output is correct |
17 |
Correct |
2 ms |
1296 KB |
Output is correct |
18 |
Correct |
2 ms |
1296 KB |
Output is correct |
19 |
Correct |
2 ms |
1296 KB |
Output is correct |
20 |
Correct |
2 ms |
1296 KB |
Output is correct |
21 |
Correct |
2 ms |
1296 KB |
Output is correct |
22 |
Correct |
2 ms |
1296 KB |
Output is correct |
23 |
Correct |
2 ms |
1296 KB |
Output is correct |
24 |
Correct |
2 ms |
1296 KB |
Output is correct |
25 |
Correct |
2 ms |
1296 KB |
Output is correct |
26 |
Correct |
2 ms |
1296 KB |
Output is correct |
27 |
Correct |
2 ms |
1296 KB |
Output is correct |
28 |
Correct |
2 ms |
1296 KB |
Output is correct |
29 |
Correct |
2 ms |
1296 KB |
Output is correct |
30 |
Correct |
2 ms |
1296 KB |
Output is correct |
31 |
Correct |
2 ms |
1296 KB |
Output is correct |
32 |
Correct |
137 ms |
1712 KB |
Output is correct |
33 |
Correct |
292 ms |
1768 KB |
Output is correct |
34 |
Correct |
431 ms |
1768 KB |
Output is correct |
35 |
Correct |
12 ms |
1768 KB |
Output is correct |
36 |
Correct |
15 ms |
1768 KB |
Output is correct |
37 |
Correct |
14 ms |
1768 KB |
Output is correct |
38 |
Correct |
11 ms |
1768 KB |
Output is correct |
39 |
Correct |
13 ms |
1768 KB |
Output is correct |
40 |
Correct |
11 ms |
1768 KB |
Output is correct |
41 |
Correct |
11 ms |
1768 KB |
Output is correct |
42 |
Correct |
11 ms |
1768 KB |
Output is correct |
43 |
Correct |
10 ms |
1768 KB |
Output is correct |
44 |
Correct |
12 ms |
1768 KB |
Output is correct |
45 |
Correct |
12 ms |
1768 KB |
Output is correct |
46 |
Correct |
18 ms |
1768 KB |
Output is correct |
47 |
Correct |
13 ms |
1768 KB |
Output is correct |
48 |
Correct |
12 ms |
1768 KB |
Output is correct |
49 |
Correct |
665 ms |
1768 KB |
Output is correct |
50 |
Correct |
10 ms |
1768 KB |
Output is correct |
51 |
Correct |
12 ms |
1768 KB |
Output is correct |
52 |
Correct |
12 ms |
1768 KB |
Output is correct |
53 |
Correct |
12 ms |
1768 KB |
Output is correct |
54 |
Correct |
13 ms |
1768 KB |
Output is correct |
55 |
Correct |
13 ms |
1768 KB |
Output is correct |
56 |
Correct |
14 ms |
1768 KB |
Output is correct |
57 |
Correct |
21 ms |
1768 KB |
Output is correct |
58 |
Correct |
11 ms |
1768 KB |
Output is correct |
59 |
Correct |
12 ms |
1768 KB |
Output is correct |
60 |
Correct |
11 ms |
1768 KB |
Output is correct |
61 |
Correct |
11 ms |
1768 KB |
Output is correct |
62 |
Correct |
12 ms |
1768 KB |
Output is correct |
63 |
Correct |
12 ms |
1768 KB |
Output is correct |
64 |
Correct |
12 ms |
1768 KB |
Output is correct |
65 |
Correct |
21 ms |
1768 KB |
Output is correct |
66 |
Correct |
13 ms |
1768 KB |
Output is correct |
67 |
Correct |
12 ms |
1768 KB |
Output is correct |
68 |
Correct |
2 ms |
1768 KB |
Output is correct |
69 |
Correct |
7 ms |
1768 KB |
Output is correct |
70 |
Correct |
8 ms |
1768 KB |
Output is correct |
71 |
Correct |
9 ms |
1768 KB |
Output is correct |
72 |
Correct |
9 ms |
1768 KB |
Output is correct |
73 |
Correct |
4 ms |
1768 KB |
Output is correct |
74 |
Correct |
8 ms |
1768 KB |
Output is correct |
75 |
Execution timed out |
2050 ms |
1768 KB |
Time limit exceeded |
76 |
Halted |
0 ms |
0 KB |
- |