#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 |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4936 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5204 KB |
Output is correct |
6 |
Correct |
3 ms |
5096 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5096 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5204 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5204 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4932 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
86 ms |
22468 KB |
Output is correct |
4 |
Correct |
90 ms |
20976 KB |
Output is correct |
5 |
Correct |
102 ms |
23740 KB |
Output is correct |
6 |
Correct |
97 ms |
24240 KB |
Output is correct |
7 |
Correct |
98 ms |
24256 KB |
Output is correct |
8 |
Correct |
92 ms |
22436 KB |
Output is correct |
9 |
Correct |
88 ms |
25540 KB |
Output is correct |
10 |
Correct |
80 ms |
20472 KB |
Output is correct |
11 |
Correct |
81 ms |
21360 KB |
Output is correct |
12 |
Correct |
93 ms |
21064 KB |
Output is correct |
13 |
Correct |
76 ms |
20804 KB |
Output is correct |
14 |
Correct |
86 ms |
20968 KB |
Output is correct |
15 |
Correct |
86 ms |
22468 KB |
Output is correct |
16 |
Correct |
60 ms |
21568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
107 ms |
25164 KB |
Output is correct |
3 |
Correct |
98 ms |
25204 KB |
Output is correct |
4 |
Correct |
86 ms |
22536 KB |
Output is correct |
5 |
Correct |
84 ms |
20904 KB |
Output is correct |
6 |
Correct |
99 ms |
25264 KB |
Output is correct |
7 |
Correct |
79 ms |
22516 KB |
Output is correct |
8 |
Correct |
80 ms |
22448 KB |
Output is correct |
9 |
Correct |
68 ms |
21620 KB |
Output is correct |
10 |
Correct |
80 ms |
21368 KB |
Output is correct |
11 |
Correct |
85 ms |
20976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
103 ms |
22980 KB |
Output is correct |
3 |
Correct |
104 ms |
23332 KB |
Output is correct |
4 |
Correct |
113 ms |
24392 KB |
Output is correct |
5 |
Correct |
108 ms |
25280 KB |
Output is correct |
6 |
Correct |
100 ms |
23204 KB |
Output is correct |
7 |
Correct |
83 ms |
22408 KB |
Output is correct |
8 |
Correct |
71 ms |
21188 KB |
Output is correct |
9 |
Correct |
69 ms |
15564 KB |
Output is correct |
10 |
Correct |
98 ms |
24460 KB |
Output is correct |
11 |
Correct |
86 ms |
20940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4936 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5204 KB |
Output is correct |
6 |
Correct |
3 ms |
5096 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5096 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5204 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5204 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
2 ms |
4932 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
86 ms |
22468 KB |
Output is correct |
18 |
Correct |
90 ms |
20976 KB |
Output is correct |
19 |
Correct |
102 ms |
23740 KB |
Output is correct |
20 |
Correct |
97 ms |
24240 KB |
Output is correct |
21 |
Correct |
98 ms |
24256 KB |
Output is correct |
22 |
Correct |
92 ms |
22436 KB |
Output is correct |
23 |
Correct |
88 ms |
25540 KB |
Output is correct |
24 |
Correct |
80 ms |
20472 KB |
Output is correct |
25 |
Correct |
81 ms |
21360 KB |
Output is correct |
26 |
Correct |
93 ms |
21064 KB |
Output is correct |
27 |
Correct |
76 ms |
20804 KB |
Output is correct |
28 |
Correct |
86 ms |
20968 KB |
Output is correct |
29 |
Correct |
86 ms |
22468 KB |
Output is correct |
30 |
Correct |
60 ms |
21568 KB |
Output is correct |
31 |
Correct |
3 ms |
4948 KB |
Output is correct |
32 |
Correct |
107 ms |
25164 KB |
Output is correct |
33 |
Correct |
98 ms |
25204 KB |
Output is correct |
34 |
Correct |
86 ms |
22536 KB |
Output is correct |
35 |
Correct |
84 ms |
20904 KB |
Output is correct |
36 |
Correct |
99 ms |
25264 KB |
Output is correct |
37 |
Correct |
79 ms |
22516 KB |
Output is correct |
38 |
Correct |
80 ms |
22448 KB |
Output is correct |
39 |
Correct |
68 ms |
21620 KB |
Output is correct |
40 |
Correct |
80 ms |
21368 KB |
Output is correct |
41 |
Correct |
85 ms |
20976 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
103 ms |
22980 KB |
Output is correct |
44 |
Correct |
104 ms |
23332 KB |
Output is correct |
45 |
Correct |
113 ms |
24392 KB |
Output is correct |
46 |
Correct |
108 ms |
25280 KB |
Output is correct |
47 |
Correct |
100 ms |
23204 KB |
Output is correct |
48 |
Correct |
83 ms |
22408 KB |
Output is correct |
49 |
Correct |
71 ms |
21188 KB |
Output is correct |
50 |
Correct |
69 ms |
15564 KB |
Output is correct |
51 |
Correct |
98 ms |
24460 KB |
Output is correct |
52 |
Correct |
86 ms |
20940 KB |
Output is correct |
53 |
Correct |
2 ms |
4948 KB |
Output is correct |
54 |
Correct |
2 ms |
4948 KB |
Output is correct |
55 |
Correct |
2 ms |
4932 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 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 |
5076 KB |
Output is correct |
60 |
Correct |
3 ms |
5076 KB |
Output is correct |
61 |
Correct |
3 ms |
5200 KB |
Output is correct |
62 |
Correct |
3 ms |
5204 KB |
Output is correct |
63 |
Correct |
3 ms |
5108 KB |
Output is correct |
64 |
Correct |
3 ms |
5092 KB |
Output is correct |
65 |
Correct |
3 ms |
5076 KB |
Output is correct |
66 |
Correct |
3 ms |
5076 KB |
Output is correct |
67 |
Correct |
84 ms |
22460 KB |
Output is correct |
68 |
Correct |
77 ms |
20964 KB |
Output is correct |
69 |
Correct |
90 ms |
23684 KB |
Output is correct |
70 |
Correct |
97 ms |
24312 KB |
Output is correct |
71 |
Correct |
93 ms |
24320 KB |
Output is correct |
72 |
Correct |
90 ms |
22408 KB |
Output is correct |
73 |
Correct |
87 ms |
25452 KB |
Output is correct |
74 |
Correct |
98 ms |
20504 KB |
Output is correct |
75 |
Correct |
83 ms |
21440 KB |
Output is correct |
76 |
Correct |
84 ms |
21112 KB |
Output is correct |
77 |
Correct |
76 ms |
20832 KB |
Output is correct |
78 |
Correct |
82 ms |
20964 KB |
Output is correct |
79 |
Correct |
80 ms |
22508 KB |
Output is correct |
80 |
Correct |
61 ms |
21644 KB |
Output is correct |
81 |
Correct |
104 ms |
25100 KB |
Output is correct |
82 |
Correct |
98 ms |
25200 KB |
Output is correct |
83 |
Correct |
95 ms |
22500 KB |
Output is correct |
84 |
Correct |
77 ms |
20888 KB |
Output is correct |
85 |
Correct |
99 ms |
25348 KB |
Output is correct |
86 |
Correct |
79 ms |
22532 KB |
Output is correct |
87 |
Correct |
80 ms |
22504 KB |
Output is correct |
88 |
Correct |
80 ms |
21348 KB |
Output is correct |
89 |
Correct |
93 ms |
20940 KB |
Output is correct |
90 |
Correct |
107 ms |
22980 KB |
Output is correct |
91 |
Correct |
107 ms |
23416 KB |
Output is correct |
92 |
Correct |
108 ms |
24304 KB |
Output is correct |
93 |
Correct |
117 ms |
25324 KB |
Output is correct |
94 |
Correct |
100 ms |
23288 KB |
Output is correct |
95 |
Correct |
85 ms |
22432 KB |
Output is correct |
96 |
Correct |
74 ms |
21200 KB |
Output is correct |
97 |
Correct |
67 ms |
15660 KB |
Output is correct |
98 |
Correct |
107 ms |
24468 KB |
Output is correct |
99 |
Correct |
91 ms |
20976 KB |
Output is correct |
100 |
Correct |
49 ms |
9468 KB |
Output is correct |
101 |
Correct |
106 ms |
23880 KB |
Output is correct |
102 |
Correct |
93 ms |
20416 KB |
Output is correct |
103 |
Correct |
93 ms |
20212 KB |
Output is correct |
104 |
Correct |
100 ms |
22520 KB |
Output is correct |