#include "bits/stdc++.h"
using namespace std;
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif
using ll = long long;
ll s[200005];
int par[200005];
ll sz[200005];
vector<int> tracker[200005];
bool able[200005];
int findset(int i) {
return (par[i] == i ? i : par[i] = findset(par[i]));
}
void merge(int a, int b) {
if (a == b) return;
if (tracker[a].size() > tracker[b].size()) swap(a, b);
for (auto cur : tracker[a]) tracker[b].push_back(cur);
par[a] = b;
sz[b] += sz[a];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("", "r", stdin);
// freopen("", "w", stdout);
int n, m; cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> s[i];
for (int i = 1; i <= n; i++) {
par[i] = i;
sz[i] = s[i];
tracker[i].push_back(i);
}
vector<pair<int, int>> edges;
for (int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
if (s[a] < s[b]) edges.emplace_back(a, b);
else edges.emplace_back(b, a);
}
sort(edges.begin(), edges.end(), [](pair<int, int> a, pair<int, int> b) {
if (s[a.second] == s[b.second]) {
return s[a.first] < s[b.first];
}
return s[a.second] < s[b.second];
});
for (int i = 1; i <= n; i++) able[i] =true;
for (auto edge : edges) {
int a = findset(edge.first), b = findset(edge.second);
// check if edge.first -> edge.second
// if (a == b) continue;
if (sz[a] >= s[edge.second]) {
// still ok
merge(a, b);
} else {
for (auto cur : tracker[a]) {
able[cur] = false;
}
tracker[a].clear(); tracker[a].shrink_to_fit();
merge(a, b);
}
}
for (int i = 1; i <= n; i++) {
if (able[i]) cout << "1";
else cout << "0";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 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 |
4 ms |
5204 KB |
Output is correct |
11 |
Correct |
4 ms |
5076 KB |
Output is correct |
12 |
Correct |
4 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5204 KB |
Output is correct |
14 |
Correct |
4 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
110 ms |
18648 KB |
Output is correct |
4 |
Correct |
116 ms |
24364 KB |
Output is correct |
5 |
Correct |
117 ms |
19008 KB |
Output is correct |
6 |
Correct |
123 ms |
19600 KB |
Output is correct |
7 |
Correct |
118 ms |
19712 KB |
Output is correct |
8 |
Correct |
124 ms |
22648 KB |
Output is correct |
9 |
Correct |
95 ms |
18488 KB |
Output is correct |
10 |
Correct |
84 ms |
17344 KB |
Output is correct |
11 |
Correct |
95 ms |
18896 KB |
Output is correct |
12 |
Correct |
117 ms |
18812 KB |
Output is correct |
13 |
Correct |
124 ms |
25384 KB |
Output is correct |
14 |
Correct |
117 ms |
24588 KB |
Output is correct |
15 |
Correct |
88 ms |
18860 KB |
Output is correct |
16 |
Correct |
64 ms |
18828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
148 ms |
20664 KB |
Output is correct |
3 |
Correct |
149 ms |
20800 KB |
Output is correct |
4 |
Correct |
130 ms |
25116 KB |
Output is correct |
5 |
Correct |
122 ms |
25300 KB |
Output is correct |
6 |
Correct |
141 ms |
20572 KB |
Output is correct |
7 |
Correct |
89 ms |
18948 KB |
Output is correct |
8 |
Correct |
89 ms |
18864 KB |
Output is correct |
9 |
Correct |
62 ms |
18752 KB |
Output is correct |
10 |
Correct |
91 ms |
17976 KB |
Output is correct |
11 |
Correct |
132 ms |
21816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
133 ms |
18704 KB |
Output is correct |
3 |
Correct |
137 ms |
19120 KB |
Output is correct |
4 |
Correct |
137 ms |
19996 KB |
Output is correct |
5 |
Correct |
121 ms |
21796 KB |
Output is correct |
6 |
Correct |
116 ms |
19692 KB |
Output is correct |
7 |
Correct |
90 ms |
18908 KB |
Output is correct |
8 |
Correct |
74 ms |
19760 KB |
Output is correct |
9 |
Correct |
70 ms |
12296 KB |
Output is correct |
10 |
Correct |
117 ms |
22560 KB |
Output is correct |
11 |
Correct |
122 ms |
21788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 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 |
4 ms |
5204 KB |
Output is correct |
11 |
Correct |
4 ms |
5076 KB |
Output is correct |
12 |
Correct |
4 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5204 KB |
Output is correct |
14 |
Correct |
4 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
110 ms |
18648 KB |
Output is correct |
18 |
Correct |
116 ms |
24364 KB |
Output is correct |
19 |
Correct |
117 ms |
19008 KB |
Output is correct |
20 |
Correct |
123 ms |
19600 KB |
Output is correct |
21 |
Correct |
118 ms |
19712 KB |
Output is correct |
22 |
Correct |
124 ms |
22648 KB |
Output is correct |
23 |
Correct |
95 ms |
18488 KB |
Output is correct |
24 |
Correct |
84 ms |
17344 KB |
Output is correct |
25 |
Correct |
95 ms |
18896 KB |
Output is correct |
26 |
Correct |
117 ms |
18812 KB |
Output is correct |
27 |
Correct |
124 ms |
25384 KB |
Output is correct |
28 |
Correct |
117 ms |
24588 KB |
Output is correct |
29 |
Correct |
88 ms |
18860 KB |
Output is correct |
30 |
Correct |
64 ms |
18828 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Correct |
148 ms |
20664 KB |
Output is correct |
33 |
Correct |
149 ms |
20800 KB |
Output is correct |
34 |
Correct |
130 ms |
25116 KB |
Output is correct |
35 |
Correct |
122 ms |
25300 KB |
Output is correct |
36 |
Correct |
141 ms |
20572 KB |
Output is correct |
37 |
Correct |
89 ms |
18948 KB |
Output is correct |
38 |
Correct |
89 ms |
18864 KB |
Output is correct |
39 |
Correct |
62 ms |
18752 KB |
Output is correct |
40 |
Correct |
91 ms |
17976 KB |
Output is correct |
41 |
Correct |
132 ms |
21816 KB |
Output is correct |
42 |
Correct |
2 ms |
4948 KB |
Output is correct |
43 |
Correct |
133 ms |
18704 KB |
Output is correct |
44 |
Correct |
137 ms |
19120 KB |
Output is correct |
45 |
Correct |
137 ms |
19996 KB |
Output is correct |
46 |
Correct |
121 ms |
21796 KB |
Output is correct |
47 |
Correct |
116 ms |
19692 KB |
Output is correct |
48 |
Correct |
90 ms |
18908 KB |
Output is correct |
49 |
Correct |
74 ms |
19760 KB |
Output is correct |
50 |
Correct |
70 ms |
12296 KB |
Output is correct |
51 |
Correct |
117 ms |
22560 KB |
Output is correct |
52 |
Correct |
122 ms |
21788 KB |
Output is correct |
53 |
Correct |
2 ms |
4948 KB |
Output is correct |
54 |
Correct |
2 ms |
4948 KB |
Output is correct |
55 |
Correct |
3 ms |
4948 KB |
Output is correct |
56 |
Correct |
4 ms |
5076 KB |
Output is correct |
57 |
Correct |
3 ms |
5076 KB |
Output is correct |
58 |
Correct |
3 ms |
5076 KB |
Output is correct |
59 |
Correct |
4 ms |
5132 KB |
Output is correct |
60 |
Correct |
3 ms |
5076 KB |
Output is correct |
61 |
Correct |
3 ms |
5076 KB |
Output is correct |
62 |
Correct |
3 ms |
5076 KB |
Output is correct |
63 |
Correct |
3 ms |
5076 KB |
Output is correct |
64 |
Correct |
3 ms |
5076 KB |
Output is correct |
65 |
Correct |
3 ms |
5204 KB |
Output is correct |
66 |
Correct |
3 ms |
5076 KB |
Output is correct |
67 |
Correct |
102 ms |
18644 KB |
Output is correct |
68 |
Correct |
122 ms |
24316 KB |
Output is correct |
69 |
Correct |
119 ms |
19008 KB |
Output is correct |
70 |
Correct |
120 ms |
19664 KB |
Output is correct |
71 |
Correct |
129 ms |
19640 KB |
Output is correct |
72 |
Correct |
124 ms |
22712 KB |
Output is correct |
73 |
Correct |
98 ms |
18540 KB |
Output is correct |
74 |
Correct |
84 ms |
17264 KB |
Output is correct |
75 |
Correct |
88 ms |
18936 KB |
Output is correct |
76 |
Correct |
153 ms |
18820 KB |
Output is correct |
77 |
Correct |
130 ms |
25400 KB |
Output is correct |
78 |
Correct |
119 ms |
24636 KB |
Output is correct |
79 |
Correct |
95 ms |
18972 KB |
Output is correct |
80 |
Correct |
66 ms |
18900 KB |
Output is correct |
81 |
Correct |
136 ms |
20668 KB |
Output is correct |
82 |
Correct |
142 ms |
20728 KB |
Output is correct |
83 |
Correct |
137 ms |
25108 KB |
Output is correct |
84 |
Correct |
129 ms |
25404 KB |
Output is correct |
85 |
Correct |
141 ms |
20568 KB |
Output is correct |
86 |
Correct |
92 ms |
18860 KB |
Output is correct |
87 |
Correct |
92 ms |
18852 KB |
Output is correct |
88 |
Correct |
94 ms |
18040 KB |
Output is correct |
89 |
Correct |
128 ms |
21892 KB |
Output is correct |
90 |
Correct |
132 ms |
18652 KB |
Output is correct |
91 |
Correct |
133 ms |
19096 KB |
Output is correct |
92 |
Correct |
139 ms |
19936 KB |
Output is correct |
93 |
Correct |
132 ms |
21812 KB |
Output is correct |
94 |
Correct |
113 ms |
19652 KB |
Output is correct |
95 |
Correct |
89 ms |
18880 KB |
Output is correct |
96 |
Correct |
77 ms |
19768 KB |
Output is correct |
97 |
Correct |
70 ms |
12308 KB |
Output is correct |
98 |
Correct |
130 ms |
22572 KB |
Output is correct |
99 |
Correct |
128 ms |
21700 KB |
Output is correct |
100 |
Correct |
54 ms |
7368 KB |
Output is correct |
101 |
Correct |
145 ms |
19320 KB |
Output is correct |
102 |
Correct |
99 ms |
17052 KB |
Output is correct |
103 |
Correct |
121 ms |
16436 KB |
Output is correct |
104 |
Correct |
136 ms |
18300 KB |
Output is correct |