#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
const int N = 2e5;
int e[N];
int find(int i) {
return e[i] < 0 ? i : e[i] = find(e[i]);
}
void link(int i, int j) {
i = find(i), j = find(j);
if (e[i] > e[j])
swap(i, j);
e[i] += e[j], e[j] = i;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
static int s[N];
for (int i = 0; i < n; i++)
cin >> s[i];
vector<array<int, 3>> ed(m);
for (auto &[v, i, j] : ed) {
cin >> i >> j, i--, j--;
v = max(s[i], s[j]);
}
sort(ed.begin(), ed.end());
static vector<int> win[N];
static long long sm[N];
for (int i = 0; i < n; i++)
e[i] = -1, sm[i] = s[i], win[i].push_back(i);
for (auto [w, i, j] : ed) {
int u = find(i), v = find(j);
if (u == v)
continue;
link(i, j);
int t = find(i);
if (sm[u] < s[j])
swap(win[t], win[v]);
else if (sm[v] < s[i])
swap(win[t], win[u]);
else {
if (win[v].size() > win[u].size())
swap(win[u], win[v]);
for (int i : win[v])
win[u].push_back(i);
swap(win[t], win[u]);
}
sm[t] = sm[u] + sm[v];
}
static bool w[N];
for (int i : win[find(0)])
w[i] = 1;
for (int i = 0; i < n; i++)
cout << w[i];
cout << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5204 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5204 KB |
Output is correct |
11 |
Correct |
3 ms |
5204 KB |
Output is correct |
12 |
Correct |
4 ms |
5204 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4936 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
100 ms |
22464 KB |
Output is correct |
4 |
Correct |
93 ms |
20932 KB |
Output is correct |
5 |
Correct |
121 ms |
23876 KB |
Output is correct |
6 |
Correct |
121 ms |
24252 KB |
Output is correct |
7 |
Correct |
114 ms |
24352 KB |
Output is correct |
8 |
Correct |
119 ms |
22412 KB |
Output is correct |
9 |
Correct |
107 ms |
25436 KB |
Output is correct |
10 |
Correct |
95 ms |
20472 KB |
Output is correct |
11 |
Correct |
93 ms |
21460 KB |
Output is correct |
12 |
Correct |
107 ms |
21096 KB |
Output is correct |
13 |
Correct |
98 ms |
20832 KB |
Output is correct |
14 |
Correct |
95 ms |
20932 KB |
Output is correct |
15 |
Correct |
101 ms |
22464 KB |
Output is correct |
16 |
Correct |
79 ms |
21580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
134 ms |
25144 KB |
Output is correct |
3 |
Correct |
129 ms |
25152 KB |
Output is correct |
4 |
Correct |
102 ms |
22628 KB |
Output is correct |
5 |
Correct |
90 ms |
20844 KB |
Output is correct |
6 |
Correct |
131 ms |
25276 KB |
Output is correct |
7 |
Correct |
100 ms |
22428 KB |
Output is correct |
8 |
Correct |
100 ms |
22492 KB |
Output is correct |
9 |
Correct |
97 ms |
21576 KB |
Output is correct |
10 |
Correct |
104 ms |
21352 KB |
Output is correct |
11 |
Correct |
110 ms |
20980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4936 KB |
Output is correct |
2 |
Correct |
136 ms |
23000 KB |
Output is correct |
3 |
Correct |
139 ms |
23416 KB |
Output is correct |
4 |
Correct |
145 ms |
24352 KB |
Output is correct |
5 |
Correct |
139 ms |
25304 KB |
Output is correct |
6 |
Correct |
127 ms |
23236 KB |
Output is correct |
7 |
Correct |
97 ms |
22456 KB |
Output is correct |
8 |
Correct |
93 ms |
21200 KB |
Output is correct |
9 |
Correct |
83 ms |
15652 KB |
Output is correct |
10 |
Correct |
128 ms |
24428 KB |
Output is correct |
11 |
Correct |
102 ms |
20972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5204 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5204 KB |
Output is correct |
11 |
Correct |
3 ms |
5204 KB |
Output is correct |
12 |
Correct |
4 ms |
5204 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5080 KB |
Output is correct |
15 |
Correct |
3 ms |
4936 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
100 ms |
22464 KB |
Output is correct |
18 |
Correct |
93 ms |
20932 KB |
Output is correct |
19 |
Correct |
121 ms |
23876 KB |
Output is correct |
20 |
Correct |
121 ms |
24252 KB |
Output is correct |
21 |
Correct |
114 ms |
24352 KB |
Output is correct |
22 |
Correct |
119 ms |
22412 KB |
Output is correct |
23 |
Correct |
107 ms |
25436 KB |
Output is correct |
24 |
Correct |
95 ms |
20472 KB |
Output is correct |
25 |
Correct |
93 ms |
21460 KB |
Output is correct |
26 |
Correct |
107 ms |
21096 KB |
Output is correct |
27 |
Correct |
98 ms |
20832 KB |
Output is correct |
28 |
Correct |
95 ms |
20932 KB |
Output is correct |
29 |
Correct |
101 ms |
22464 KB |
Output is correct |
30 |
Correct |
79 ms |
21580 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Correct |
134 ms |
25144 KB |
Output is correct |
33 |
Correct |
129 ms |
25152 KB |
Output is correct |
34 |
Correct |
102 ms |
22628 KB |
Output is correct |
35 |
Correct |
90 ms |
20844 KB |
Output is correct |
36 |
Correct |
131 ms |
25276 KB |
Output is correct |
37 |
Correct |
100 ms |
22428 KB |
Output is correct |
38 |
Correct |
100 ms |
22492 KB |
Output is correct |
39 |
Correct |
97 ms |
21576 KB |
Output is correct |
40 |
Correct |
104 ms |
21352 KB |
Output is correct |
41 |
Correct |
110 ms |
20980 KB |
Output is correct |
42 |
Correct |
3 ms |
4936 KB |
Output is correct |
43 |
Correct |
136 ms |
23000 KB |
Output is correct |
44 |
Correct |
139 ms |
23416 KB |
Output is correct |
45 |
Correct |
145 ms |
24352 KB |
Output is correct |
46 |
Correct |
139 ms |
25304 KB |
Output is correct |
47 |
Correct |
127 ms |
23236 KB |
Output is correct |
48 |
Correct |
97 ms |
22456 KB |
Output is correct |
49 |
Correct |
93 ms |
21200 KB |
Output is correct |
50 |
Correct |
83 ms |
15652 KB |
Output is correct |
51 |
Correct |
128 ms |
24428 KB |
Output is correct |
52 |
Correct |
102 ms |
20972 KB |
Output is correct |
53 |
Correct |
2 ms |
4948 KB |
Output is correct |
54 |
Correct |
3 ms |
4932 KB |
Output is correct |
55 |
Correct |
3 ms |
4932 KB |
Output is correct |
56 |
Correct |
5 ms |
5204 KB |
Output is correct |
57 |
Correct |
3 ms |
5204 KB |
Output is correct |
58 |
Correct |
3 ms |
5076 KB |
Output is correct |
59 |
Correct |
3 ms |
5072 KB |
Output is correct |
60 |
Correct |
4 ms |
5072 KB |
Output is correct |
61 |
Correct |
4 ms |
5076 KB |
Output is correct |
62 |
Correct |
3 ms |
5204 KB |
Output is correct |
63 |
Correct |
4 ms |
5200 KB |
Output is correct |
64 |
Correct |
3 ms |
5204 KB |
Output is correct |
65 |
Correct |
3 ms |
5076 KB |
Output is correct |
66 |
Correct |
4 ms |
5076 KB |
Output is correct |
67 |
Correct |
102 ms |
22432 KB |
Output is correct |
68 |
Correct |
94 ms |
20972 KB |
Output is correct |
69 |
Correct |
111 ms |
23716 KB |
Output is correct |
70 |
Correct |
115 ms |
24232 KB |
Output is correct |
71 |
Correct |
113 ms |
24252 KB |
Output is correct |
72 |
Correct |
110 ms |
22428 KB |
Output is correct |
73 |
Correct |
109 ms |
25452 KB |
Output is correct |
74 |
Correct |
92 ms |
20472 KB |
Output is correct |
75 |
Correct |
93 ms |
21396 KB |
Output is correct |
76 |
Correct |
108 ms |
21136 KB |
Output is correct |
77 |
Correct |
92 ms |
20720 KB |
Output is correct |
78 |
Correct |
94 ms |
20960 KB |
Output is correct |
79 |
Correct |
100 ms |
22476 KB |
Output is correct |
80 |
Correct |
76 ms |
21568 KB |
Output is correct |
81 |
Correct |
128 ms |
25100 KB |
Output is correct |
82 |
Correct |
136 ms |
25172 KB |
Output is correct |
83 |
Correct |
99 ms |
22448 KB |
Output is correct |
84 |
Correct |
90 ms |
20832 KB |
Output is correct |
85 |
Correct |
127 ms |
25324 KB |
Output is correct |
86 |
Correct |
96 ms |
22536 KB |
Output is correct |
87 |
Correct |
98 ms |
22456 KB |
Output is correct |
88 |
Correct |
101 ms |
21352 KB |
Output is correct |
89 |
Correct |
117 ms |
20972 KB |
Output is correct |
90 |
Correct |
136 ms |
23152 KB |
Output is correct |
91 |
Correct |
145 ms |
23340 KB |
Output is correct |
92 |
Correct |
137 ms |
24392 KB |
Output is correct |
93 |
Correct |
137 ms |
25356 KB |
Output is correct |
94 |
Correct |
132 ms |
23324 KB |
Output is correct |
95 |
Correct |
102 ms |
22344 KB |
Output is correct |
96 |
Correct |
85 ms |
21140 KB |
Output is correct |
97 |
Correct |
80 ms |
15580 KB |
Output is correct |
98 |
Correct |
137 ms |
24476 KB |
Output is correct |
99 |
Correct |
100 ms |
20924 KB |
Output is correct |
100 |
Correct |
59 ms |
9440 KB |
Output is correct |
101 |
Correct |
127 ms |
23824 KB |
Output is correct |
102 |
Correct |
111 ms |
20420 KB |
Output is correct |
103 |
Correct |
107 ms |
20272 KB |
Output is correct |
104 |
Correct |
123 ms |
22452 KB |
Output is correct |