#include "train.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
const int nmax = 5005;
const int mmax = 20005;
int n, m;
vector<int>nod[nmax], nod1[nmax];
void computeset(vector<int>&vecc, vector<int>&marked, vector<int>&host, int player){
vector<int>cnt(n);
for(int i=0;i<n;i++){
for(auto it : nod[i]){
if(marked[it] || vecc[it]){
cnt[i]++;
}
}
}
vector<int>procesare;
for(int i=0;i<n;i++){
if(!marked[i] && !vecc[i] && host[i] != player && cnt[i] == nod[i].size()){
procesare.push_back(i);
}
else if(host[i] == player && !vecc[i] && !marked[i]){
for(auto it : nod[i]){
if(vecc[it]){
procesare.push_back(i);
}
}
}
}
while(procesare.size()){
auto it = procesare.back();
procesare.pop_back();
if(vecc[it] == 1){
continue;
}
vecc[it] = 1;
for(auto it1 : nod1[it]){
if(!marked[it1] && !vecc[it1]){
if(host[it1] == player){
procesare.push_back(it1);
}
else{
cnt[it1]++;
if(cnt[it1] == (int)nod[it1].size()){
procesare.push_back(it1);
}
}
}
}
}
}
void compute(vector<int>&marked, vector<int>&host, vector<int>&baterii){
int cnt = 0;
vector<int>r(n);
for(int i=0;i<n;i++){
if(baterii[i] && !marked[i]){
r[i] = 1;
cnt++;
}
}
if(!cnt){
for(int i=0;i<n;i++){
marked[i] = 1;
}
return;
}
computeset(r, marked, host, 1);
vector<int>b(n);
cnt = 0;
for(int i=0;i<n;i++){
if(!marked[i] && !r[i]){
b[i] = 1;
cnt++;
}
}
if(!cnt){
return;
}
computeset(b, marked, host, 0);
for(int i=0;i<n;i++){
if(b[i] == 1){
marked[i] = 1;
}
}
compute(marked, host, baterii);
return;
}
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++){
nod[u[i]].push_back(v[i]);
nod1[v[i]].push_back(u[i]);
}
vector<int>ans(n);
compute(ans, a, r);
for(int i=0;i<n;i++) ans[i] ^= 1;
return ans;
}
Compilation message
train.cpp: In function 'void computeset(std::vector<int>&, std::vector<int>&, std::vector<int>&, int)':
train.cpp:31:66: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | if(!marked[i] && !vecc[i] && host[i] != player && cnt[i] == nod[i].size()){
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1228 KB |
Output is correct |
2 |
Correct |
8 ms |
1436 KB |
Output is correct |
3 |
Correct |
7 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
1356 KB |
Output is correct |
5 |
Correct |
6 ms |
1228 KB |
Output is correct |
6 |
Correct |
8 ms |
1220 KB |
Output is correct |
7 |
Correct |
5 ms |
1208 KB |
Output is correct |
8 |
Correct |
6 ms |
1356 KB |
Output is correct |
9 |
Correct |
6 ms |
1204 KB |
Output is correct |
10 |
Correct |
5 ms |
1176 KB |
Output is correct |
11 |
Correct |
5 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
532 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
536 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
242 ms |
20984 KB |
Output is correct |
2 |
Correct |
471 ms |
40900 KB |
Output is correct |
3 |
Correct |
649 ms |
60436 KB |
Output is correct |
4 |
Correct |
11 ms |
1612 KB |
Output is correct |
5 |
Correct |
12 ms |
1740 KB |
Output is correct |
6 |
Correct |
12 ms |
1764 KB |
Output is correct |
7 |
Correct |
13 ms |
1564 KB |
Output is correct |
8 |
Correct |
10 ms |
1644 KB |
Output is correct |
9 |
Correct |
12 ms |
1564 KB |
Output is correct |
10 |
Correct |
12 ms |
1484 KB |
Output is correct |
11 |
Correct |
10 ms |
1468 KB |
Output is correct |
12 |
Correct |
12 ms |
1484 KB |
Output is correct |
13 |
Correct |
13 ms |
1612 KB |
Output is correct |
14 |
Correct |
12 ms |
1612 KB |
Output is correct |
15 |
Correct |
10 ms |
1612 KB |
Output is correct |
16 |
Correct |
10 ms |
1664 KB |
Output is correct |
17 |
Correct |
12 ms |
1604 KB |
Output is correct |
18 |
Correct |
733 ms |
99428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1192 KB |
Output is correct |
2 |
Correct |
9 ms |
1484 KB |
Output is correct |
3 |
Correct |
9 ms |
1568 KB |
Output is correct |
4 |
Correct |
9 ms |
1612 KB |
Output is correct |
5 |
Correct |
9 ms |
1564 KB |
Output is correct |
6 |
Correct |
13 ms |
1568 KB |
Output is correct |
7 |
Correct |
10 ms |
1612 KB |
Output is correct |
8 |
Correct |
9 ms |
1484 KB |
Output is correct |
9 |
Correct |
11 ms |
1476 KB |
Output is correct |
10 |
Correct |
12 ms |
1612 KB |
Output is correct |
11 |
Correct |
9 ms |
1612 KB |
Output is correct |
12 |
Correct |
9 ms |
1612 KB |
Output is correct |
13 |
Correct |
10 ms |
1572 KB |
Output is correct |
14 |
Correct |
9 ms |
1532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1368 KB |
Output is correct |
2 |
Correct |
9 ms |
1612 KB |
Output is correct |
3 |
Correct |
11 ms |
1640 KB |
Output is correct |
4 |
Correct |
9 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
5 ms |
1140 KB |
Output is correct |
7 |
Correct |
6 ms |
1228 KB |
Output is correct |
8 |
Correct |
6 ms |
1312 KB |
Output is correct |
9 |
Correct |
8 ms |
1228 KB |
Output is correct |
10 |
Correct |
3 ms |
736 KB |
Output is correct |
11 |
Correct |
6 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1228 KB |
Output is correct |
2 |
Correct |
8 ms |
1436 KB |
Output is correct |
3 |
Correct |
7 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
1356 KB |
Output is correct |
5 |
Correct |
6 ms |
1228 KB |
Output is correct |
6 |
Correct |
8 ms |
1220 KB |
Output is correct |
7 |
Correct |
5 ms |
1208 KB |
Output is correct |
8 |
Correct |
6 ms |
1356 KB |
Output is correct |
9 |
Correct |
6 ms |
1204 KB |
Output is correct |
10 |
Correct |
5 ms |
1176 KB |
Output is correct |
11 |
Correct |
5 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
532 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
536 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
242 ms |
20984 KB |
Output is correct |
33 |
Correct |
471 ms |
40900 KB |
Output is correct |
34 |
Correct |
649 ms |
60436 KB |
Output is correct |
35 |
Correct |
11 ms |
1612 KB |
Output is correct |
36 |
Correct |
12 ms |
1740 KB |
Output is correct |
37 |
Correct |
12 ms |
1764 KB |
Output is correct |
38 |
Correct |
13 ms |
1564 KB |
Output is correct |
39 |
Correct |
10 ms |
1644 KB |
Output is correct |
40 |
Correct |
12 ms |
1564 KB |
Output is correct |
41 |
Correct |
12 ms |
1484 KB |
Output is correct |
42 |
Correct |
10 ms |
1468 KB |
Output is correct |
43 |
Correct |
12 ms |
1484 KB |
Output is correct |
44 |
Correct |
13 ms |
1612 KB |
Output is correct |
45 |
Correct |
12 ms |
1612 KB |
Output is correct |
46 |
Correct |
10 ms |
1612 KB |
Output is correct |
47 |
Correct |
10 ms |
1664 KB |
Output is correct |
48 |
Correct |
12 ms |
1604 KB |
Output is correct |
49 |
Correct |
733 ms |
99428 KB |
Output is correct |
50 |
Correct |
7 ms |
1192 KB |
Output is correct |
51 |
Correct |
9 ms |
1484 KB |
Output is correct |
52 |
Correct |
9 ms |
1568 KB |
Output is correct |
53 |
Correct |
9 ms |
1612 KB |
Output is correct |
54 |
Correct |
9 ms |
1564 KB |
Output is correct |
55 |
Correct |
13 ms |
1568 KB |
Output is correct |
56 |
Correct |
10 ms |
1612 KB |
Output is correct |
57 |
Correct |
9 ms |
1484 KB |
Output is correct |
58 |
Correct |
11 ms |
1476 KB |
Output is correct |
59 |
Correct |
12 ms |
1612 KB |
Output is correct |
60 |
Correct |
9 ms |
1612 KB |
Output is correct |
61 |
Correct |
9 ms |
1612 KB |
Output is correct |
62 |
Correct |
10 ms |
1572 KB |
Output is correct |
63 |
Correct |
9 ms |
1532 KB |
Output is correct |
64 |
Correct |
10 ms |
1368 KB |
Output is correct |
65 |
Correct |
9 ms |
1612 KB |
Output is correct |
66 |
Correct |
11 ms |
1640 KB |
Output is correct |
67 |
Correct |
9 ms |
1484 KB |
Output is correct |
68 |
Correct |
1 ms |
588 KB |
Output is correct |
69 |
Correct |
5 ms |
1140 KB |
Output is correct |
70 |
Correct |
6 ms |
1228 KB |
Output is correct |
71 |
Correct |
6 ms |
1312 KB |
Output is correct |
72 |
Correct |
8 ms |
1228 KB |
Output is correct |
73 |
Correct |
3 ms |
736 KB |
Output is correct |
74 |
Correct |
6 ms |
1100 KB |
Output is correct |
75 |
Correct |
262 ms |
40760 KB |
Output is correct |
76 |
Correct |
500 ms |
40900 KB |
Output is correct |
77 |
Correct |
742 ms |
60532 KB |
Output is correct |
78 |
Correct |
740 ms |
60716 KB |
Output is correct |
79 |
Correct |
737 ms |
60508 KB |
Output is correct |
80 |
Correct |
10 ms |
1612 KB |
Output is correct |
81 |
Correct |
10 ms |
1640 KB |
Output is correct |
82 |
Correct |
12 ms |
1704 KB |
Output is correct |
83 |
Correct |
16 ms |
1740 KB |
Output is correct |
84 |
Correct |
15 ms |
1720 KB |
Output is correct |
85 |
Correct |
12 ms |
1744 KB |
Output is correct |
86 |
Correct |
14 ms |
1740 KB |
Output is correct |
87 |
Correct |
11 ms |
1568 KB |
Output is correct |
88 |
Correct |
17 ms |
1904 KB |
Output is correct |
89 |
Correct |
14 ms |
1720 KB |
Output is correct |
90 |
Correct |
23 ms |
2244 KB |
Output is correct |
91 |
Correct |
22 ms |
2336 KB |
Output is correct |
92 |
Correct |
47 ms |
3480 KB |
Output is correct |
93 |
Correct |
45 ms |
3448 KB |
Output is correct |
94 |
Correct |
47 ms |
3572 KB |
Output is correct |
95 |
Correct |
52 ms |
3524 KB |
Output is correct |
96 |
Correct |
150 ms |
9324 KB |
Output is correct |
97 |
Correct |
880 ms |
56524 KB |
Output is correct |
98 |
Correct |
1366 ms |
80220 KB |
Output is correct |
99 |
Correct |
1499 ms |
98992 KB |
Output is correct |
100 |
Correct |
760 ms |
99524 KB |
Output is correct |