#include <bits/stdc++.h>
using namespace std;
const int N = 200'000 + 10;
int n, m;
int a[N];
vector<pair<int, int>> edges;
long long total[N];
int id[N];
vector<int> vt[N];
bool mk[N];
int root(int u) { return id[u] < 0 ? u : root(id[u]); }
void add(int u, int v) {
u = root(u); v = root(v);
if (u == v) return;
if (a[u] < a[v]) swap(u, v);
if (total[v] < a[u]) {
for (const auto& x : vt[v]) mk[x] = false;
vt[v].clear();
}
if (id[u] > id[v]) swap(u, v);
total[u] += total[v];
a[u] = max(a[u], a[v]);
vt[u].insert(vt[u].end(), vt[v].begin(), vt[v].end());
id[u] += id[v];
id[v] = u;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= m; ++i) {
int u, v; cin >> u >> v;
edges.push_back({u, v});
}
sort(edges.begin(), edges.end(), [&](const auto& x, const auto& y) {
return max(a[get<0>(x)], a[get<1>(x)]) < max(a[get<0>(y)], a[get<1>(y)]);
});
for (int i = 1; i <= n; ++i) {
total[i] = a[i];
vt[i] = {i};
}
memset(mk, true, sizeof mk);
memset(id, -1, sizeof id);
for (const auto& [u, v] : edges) add(u, v);
for (int i = 1; i <= n; ++i) cout << mk[i];
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
5980 KB |
Output is correct |
3 |
Correct |
2 ms |
5924 KB |
Output is correct |
4 |
Correct |
3 ms |
6236 KB |
Output is correct |
5 |
Correct |
5 ms |
6492 KB |
Output is correct |
6 |
Correct |
3 ms |
6204 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6236 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
4 ms |
6236 KB |
Output is correct |
11 |
Correct |
3 ms |
6236 KB |
Output is correct |
12 |
Correct |
4 ms |
6232 KB |
Output is correct |
13 |
Correct |
4 ms |
6236 KB |
Output is correct |
14 |
Correct |
3 ms |
6236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5980 KB |
Output is correct |
2 |
Correct |
3 ms |
5980 KB |
Output is correct |
3 |
Correct |
92 ms |
22332 KB |
Output is correct |
4 |
Correct |
80 ms |
26756 KB |
Output is correct |
5 |
Correct |
85 ms |
23756 KB |
Output is correct |
6 |
Correct |
89 ms |
24516 KB |
Output is correct |
7 |
Correct |
92 ms |
24264 KB |
Output is correct |
8 |
Correct |
91 ms |
26564 KB |
Output is correct |
9 |
Correct |
87 ms |
25028 KB |
Output is correct |
10 |
Correct |
70 ms |
19840 KB |
Output is correct |
11 |
Correct |
79 ms |
21484 KB |
Output is correct |
12 |
Correct |
76 ms |
21188 KB |
Output is correct |
13 |
Correct |
85 ms |
27672 KB |
Output is correct |
14 |
Correct |
85 ms |
26564 KB |
Output is correct |
15 |
Correct |
75 ms |
22724 KB |
Output is correct |
16 |
Correct |
60 ms |
21804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5980 KB |
Output is correct |
2 |
Correct |
94 ms |
25032 KB |
Output is correct |
3 |
Correct |
97 ms |
24840 KB |
Output is correct |
4 |
Correct |
93 ms |
28864 KB |
Output is correct |
5 |
Correct |
79 ms |
27080 KB |
Output is correct |
6 |
Correct |
98 ms |
25284 KB |
Output is correct |
7 |
Correct |
77 ms |
22648 KB |
Output is correct |
8 |
Correct |
79 ms |
22564 KB |
Output is correct |
9 |
Correct |
59 ms |
21704 KB |
Output is correct |
10 |
Correct |
73 ms |
24008 KB |
Output is correct |
11 |
Correct |
81 ms |
24264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Output is correct |
2 |
Correct |
84 ms |
23024 KB |
Output is correct |
3 |
Correct |
78 ms |
23240 KB |
Output is correct |
4 |
Correct |
88 ms |
24260 KB |
Output is correct |
5 |
Correct |
81 ms |
25800 KB |
Output is correct |
6 |
Correct |
75 ms |
23384 KB |
Output is correct |
7 |
Correct |
71 ms |
22468 KB |
Output is correct |
8 |
Correct |
66 ms |
22220 KB |
Output is correct |
9 |
Correct |
48 ms |
15300 KB |
Output is correct |
10 |
Correct |
81 ms |
25028 KB |
Output is correct |
11 |
Correct |
79 ms |
24668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
5980 KB |
Output is correct |
3 |
Correct |
2 ms |
5924 KB |
Output is correct |
4 |
Correct |
3 ms |
6236 KB |
Output is correct |
5 |
Correct |
5 ms |
6492 KB |
Output is correct |
6 |
Correct |
3 ms |
6204 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6236 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
4 ms |
6236 KB |
Output is correct |
11 |
Correct |
3 ms |
6236 KB |
Output is correct |
12 |
Correct |
4 ms |
6232 KB |
Output is correct |
13 |
Correct |
4 ms |
6236 KB |
Output is correct |
14 |
Correct |
3 ms |
6236 KB |
Output is correct |
15 |
Correct |
3 ms |
5980 KB |
Output is correct |
16 |
Correct |
3 ms |
5980 KB |
Output is correct |
17 |
Correct |
92 ms |
22332 KB |
Output is correct |
18 |
Correct |
80 ms |
26756 KB |
Output is correct |
19 |
Correct |
85 ms |
23756 KB |
Output is correct |
20 |
Correct |
89 ms |
24516 KB |
Output is correct |
21 |
Correct |
92 ms |
24264 KB |
Output is correct |
22 |
Correct |
91 ms |
26564 KB |
Output is correct |
23 |
Correct |
87 ms |
25028 KB |
Output is correct |
24 |
Correct |
70 ms |
19840 KB |
Output is correct |
25 |
Correct |
79 ms |
21484 KB |
Output is correct |
26 |
Correct |
76 ms |
21188 KB |
Output is correct |
27 |
Correct |
85 ms |
27672 KB |
Output is correct |
28 |
Correct |
85 ms |
26564 KB |
Output is correct |
29 |
Correct |
75 ms |
22724 KB |
Output is correct |
30 |
Correct |
60 ms |
21804 KB |
Output is correct |
31 |
Correct |
3 ms |
5980 KB |
Output is correct |
32 |
Correct |
94 ms |
25032 KB |
Output is correct |
33 |
Correct |
97 ms |
24840 KB |
Output is correct |
34 |
Correct |
93 ms |
28864 KB |
Output is correct |
35 |
Correct |
79 ms |
27080 KB |
Output is correct |
36 |
Correct |
98 ms |
25284 KB |
Output is correct |
37 |
Correct |
77 ms |
22648 KB |
Output is correct |
38 |
Correct |
79 ms |
22564 KB |
Output is correct |
39 |
Correct |
59 ms |
21704 KB |
Output is correct |
40 |
Correct |
73 ms |
24008 KB |
Output is correct |
41 |
Correct |
81 ms |
24264 KB |
Output is correct |
42 |
Correct |
2 ms |
5976 KB |
Output is correct |
43 |
Correct |
84 ms |
23024 KB |
Output is correct |
44 |
Correct |
78 ms |
23240 KB |
Output is correct |
45 |
Correct |
88 ms |
24260 KB |
Output is correct |
46 |
Correct |
81 ms |
25800 KB |
Output is correct |
47 |
Correct |
75 ms |
23384 KB |
Output is correct |
48 |
Correct |
71 ms |
22468 KB |
Output is correct |
49 |
Correct |
66 ms |
22220 KB |
Output is correct |
50 |
Correct |
48 ms |
15300 KB |
Output is correct |
51 |
Correct |
81 ms |
25028 KB |
Output is correct |
52 |
Correct |
79 ms |
24668 KB |
Output is correct |
53 |
Correct |
3 ms |
5980 KB |
Output is correct |
54 |
Correct |
3 ms |
6064 KB |
Output is correct |
55 |
Correct |
3 ms |
5976 KB |
Output is correct |
56 |
Correct |
4 ms |
6236 KB |
Output is correct |
57 |
Correct |
3 ms |
6236 KB |
Output is correct |
58 |
Correct |
3 ms |
6236 KB |
Output is correct |
59 |
Correct |
3 ms |
6236 KB |
Output is correct |
60 |
Correct |
3 ms |
6236 KB |
Output is correct |
61 |
Correct |
3 ms |
6232 KB |
Output is correct |
62 |
Correct |
4 ms |
6488 KB |
Output is correct |
63 |
Correct |
3 ms |
6236 KB |
Output is correct |
64 |
Correct |
3 ms |
6488 KB |
Output is correct |
65 |
Correct |
3 ms |
6236 KB |
Output is correct |
66 |
Correct |
3 ms |
6236 KB |
Output is correct |
67 |
Correct |
77 ms |
22348 KB |
Output is correct |
68 |
Correct |
75 ms |
26824 KB |
Output is correct |
69 |
Correct |
86 ms |
23748 KB |
Output is correct |
70 |
Correct |
90 ms |
24520 KB |
Output is correct |
71 |
Correct |
91 ms |
24228 KB |
Output is correct |
72 |
Correct |
90 ms |
26552 KB |
Output is correct |
73 |
Correct |
79 ms |
25036 KB |
Output is correct |
74 |
Correct |
68 ms |
19908 KB |
Output is correct |
75 |
Correct |
65 ms |
21700 KB |
Output is correct |
76 |
Correct |
71 ms |
21192 KB |
Output is correct |
77 |
Correct |
73 ms |
27724 KB |
Output is correct |
78 |
Correct |
77 ms |
26540 KB |
Output is correct |
79 |
Correct |
74 ms |
22732 KB |
Output is correct |
80 |
Correct |
54 ms |
21748 KB |
Output is correct |
81 |
Correct |
89 ms |
25028 KB |
Output is correct |
82 |
Correct |
87 ms |
24780 KB |
Output is correct |
83 |
Correct |
85 ms |
29036 KB |
Output is correct |
84 |
Correct |
81 ms |
27080 KB |
Output is correct |
85 |
Correct |
86 ms |
25288 KB |
Output is correct |
86 |
Correct |
76 ms |
22724 KB |
Output is correct |
87 |
Correct |
74 ms |
22688 KB |
Output is correct |
88 |
Correct |
80 ms |
24008 KB |
Output is correct |
89 |
Correct |
79 ms |
24264 KB |
Output is correct |
90 |
Correct |
84 ms |
22816 KB |
Output is correct |
91 |
Correct |
87 ms |
23064 KB |
Output is correct |
92 |
Correct |
98 ms |
24124 KB |
Output is correct |
93 |
Correct |
83 ms |
25852 KB |
Output is correct |
94 |
Correct |
74 ms |
23492 KB |
Output is correct |
95 |
Correct |
65 ms |
22528 KB |
Output is correct |
96 |
Correct |
58 ms |
22220 KB |
Output is correct |
97 |
Correct |
54 ms |
15176 KB |
Output is correct |
98 |
Correct |
90 ms |
25020 KB |
Output is correct |
99 |
Correct |
80 ms |
24772 KB |
Output is correct |
100 |
Correct |
38 ms |
9676 KB |
Output is correct |
101 |
Correct |
99 ms |
23436 KB |
Output is correct |
102 |
Correct |
67 ms |
20676 KB |
Output is correct |
103 |
Correct |
88 ms |
19908 KB |
Output is correct |
104 |
Correct |
96 ms |
22596 KB |
Output is correct |