#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 2e5 + 100;
vector <int> save[N];
int sz[N], p[N], ans[N];
ll sum[N], s[N];
int get(int a) {
if (p[a] == 0)
return a;
return get(p[a]);
}
void unite(int a, int b) {
a = get(a);
b = get(b);
if (a == b)
return;
if (sz[a] < sz[b]) {
swap(a, b);
}
for (auto x : save[b])
save[a].pb(x);
save[b].clear();
sz[a] += sz[b];
sum[a] += sum[b];
p[b] = a;
}
vector <int> ed[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
fill(sz, sz + 1 + n, 1);
vector <pair <ll, ll>> lst;
for (int i = 1; i <= n; i++) {
cin >> s[i];
sum[i] = s[i];
save[i].pb(i);
lst.pb({s[i], i});
}
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
ed[a].pb(b);
ed[b].pb(a);
}
sort(all(lst));
for (auto e : lst) {
int i = e.s;
for (auto x : ed[i]) {
if (s[x] > s[i])
continue;
int c = get(x);
if (sum[c] < s[i]) {
for (auto t : save[c]) {
ans[t] = 1;
}
save[c].clear();
}
unite(c, i);
}
}
for (int i = 1; i <= n; i++)
cout << !ans[i];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
15196 KB |
Output is correct |
2 |
Correct |
3 ms |
15196 KB |
Output is correct |
3 |
Correct |
4 ms |
13148 KB |
Output is correct |
4 |
Correct |
4 ms |
15456 KB |
Output is correct |
5 |
Correct |
5 ms |
15452 KB |
Output is correct |
6 |
Correct |
5 ms |
15464 KB |
Output is correct |
7 |
Correct |
4 ms |
15456 KB |
Output is correct |
8 |
Correct |
4 ms |
15456 KB |
Output is correct |
9 |
Correct |
4 ms |
15464 KB |
Output is correct |
10 |
Correct |
4 ms |
15464 KB |
Output is correct |
11 |
Correct |
4 ms |
15556 KB |
Output is correct |
12 |
Correct |
5 ms |
15464 KB |
Output is correct |
13 |
Correct |
5 ms |
15464 KB |
Output is correct |
14 |
Correct |
5 ms |
15464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
15208 KB |
Output is correct |
2 |
Correct |
4 ms |
13160 KB |
Output is correct |
3 |
Correct |
138 ms |
37788 KB |
Output is correct |
4 |
Correct |
133 ms |
36056 KB |
Output is correct |
5 |
Correct |
171 ms |
38836 KB |
Output is correct |
6 |
Correct |
183 ms |
38892 KB |
Output is correct |
7 |
Correct |
181 ms |
39096 KB |
Output is correct |
8 |
Correct |
159 ms |
37392 KB |
Output is correct |
9 |
Correct |
119 ms |
40116 KB |
Output is correct |
10 |
Correct |
112 ms |
35360 KB |
Output is correct |
11 |
Correct |
141 ms |
37952 KB |
Output is correct |
12 |
Correct |
153 ms |
36108 KB |
Output is correct |
13 |
Correct |
138 ms |
35892 KB |
Output is correct |
14 |
Correct |
117 ms |
36216 KB |
Output is correct |
15 |
Correct |
125 ms |
37632 KB |
Output is correct |
16 |
Correct |
78 ms |
37248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
13144 KB |
Output is correct |
2 |
Correct |
173 ms |
35944 KB |
Output is correct |
3 |
Correct |
173 ms |
35256 KB |
Output is correct |
4 |
Correct |
148 ms |
37624 KB |
Output is correct |
5 |
Correct |
112 ms |
35416 KB |
Output is correct |
6 |
Correct |
200 ms |
39696 KB |
Output is correct |
7 |
Correct |
145 ms |
37300 KB |
Output is correct |
8 |
Correct |
133 ms |
37456 KB |
Output is correct |
9 |
Correct |
82 ms |
37504 KB |
Output is correct |
10 |
Correct |
125 ms |
35728 KB |
Output is correct |
11 |
Correct |
158 ms |
35484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
13144 KB |
Output is correct |
2 |
Correct |
219 ms |
37588 KB |
Output is correct |
3 |
Correct |
202 ms |
37884 KB |
Output is correct |
4 |
Correct |
198 ms |
38836 KB |
Output is correct |
5 |
Correct |
222 ms |
40116 KB |
Output is correct |
6 |
Correct |
151 ms |
37696 KB |
Output is correct |
7 |
Correct |
117 ms |
38132 KB |
Output is correct |
8 |
Correct |
82 ms |
35252 KB |
Output is correct |
9 |
Correct |
89 ms |
27472 KB |
Output is correct |
10 |
Correct |
174 ms |
40820 KB |
Output is correct |
11 |
Correct |
145 ms |
36172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
15196 KB |
Output is correct |
2 |
Correct |
3 ms |
15196 KB |
Output is correct |
3 |
Correct |
4 ms |
13148 KB |
Output is correct |
4 |
Correct |
4 ms |
15456 KB |
Output is correct |
5 |
Correct |
5 ms |
15452 KB |
Output is correct |
6 |
Correct |
5 ms |
15464 KB |
Output is correct |
7 |
Correct |
4 ms |
15456 KB |
Output is correct |
8 |
Correct |
4 ms |
15456 KB |
Output is correct |
9 |
Correct |
4 ms |
15464 KB |
Output is correct |
10 |
Correct |
4 ms |
15464 KB |
Output is correct |
11 |
Correct |
4 ms |
15556 KB |
Output is correct |
12 |
Correct |
5 ms |
15464 KB |
Output is correct |
13 |
Correct |
5 ms |
15464 KB |
Output is correct |
14 |
Correct |
5 ms |
15464 KB |
Output is correct |
15 |
Correct |
3 ms |
15208 KB |
Output is correct |
16 |
Correct |
4 ms |
13160 KB |
Output is correct |
17 |
Correct |
138 ms |
37788 KB |
Output is correct |
18 |
Correct |
133 ms |
36056 KB |
Output is correct |
19 |
Correct |
171 ms |
38836 KB |
Output is correct |
20 |
Correct |
183 ms |
38892 KB |
Output is correct |
21 |
Correct |
181 ms |
39096 KB |
Output is correct |
22 |
Correct |
159 ms |
37392 KB |
Output is correct |
23 |
Correct |
119 ms |
40116 KB |
Output is correct |
24 |
Correct |
112 ms |
35360 KB |
Output is correct |
25 |
Correct |
141 ms |
37952 KB |
Output is correct |
26 |
Correct |
153 ms |
36108 KB |
Output is correct |
27 |
Correct |
138 ms |
35892 KB |
Output is correct |
28 |
Correct |
117 ms |
36216 KB |
Output is correct |
29 |
Correct |
125 ms |
37632 KB |
Output is correct |
30 |
Correct |
78 ms |
37248 KB |
Output is correct |
31 |
Correct |
3 ms |
13144 KB |
Output is correct |
32 |
Correct |
173 ms |
35944 KB |
Output is correct |
33 |
Correct |
173 ms |
35256 KB |
Output is correct |
34 |
Correct |
148 ms |
37624 KB |
Output is correct |
35 |
Correct |
112 ms |
35416 KB |
Output is correct |
36 |
Correct |
200 ms |
39696 KB |
Output is correct |
37 |
Correct |
145 ms |
37300 KB |
Output is correct |
38 |
Correct |
133 ms |
37456 KB |
Output is correct |
39 |
Correct |
82 ms |
37504 KB |
Output is correct |
40 |
Correct |
125 ms |
35728 KB |
Output is correct |
41 |
Correct |
158 ms |
35484 KB |
Output is correct |
42 |
Correct |
3 ms |
13144 KB |
Output is correct |
43 |
Correct |
219 ms |
37588 KB |
Output is correct |
44 |
Correct |
202 ms |
37884 KB |
Output is correct |
45 |
Correct |
198 ms |
38836 KB |
Output is correct |
46 |
Correct |
222 ms |
40116 KB |
Output is correct |
47 |
Correct |
151 ms |
37696 KB |
Output is correct |
48 |
Correct |
117 ms |
38132 KB |
Output is correct |
49 |
Correct |
82 ms |
35252 KB |
Output is correct |
50 |
Correct |
89 ms |
27472 KB |
Output is correct |
51 |
Correct |
174 ms |
40820 KB |
Output is correct |
52 |
Correct |
145 ms |
36172 KB |
Output is correct |
53 |
Correct |
3 ms |
15196 KB |
Output is correct |
54 |
Correct |
4 ms |
15196 KB |
Output is correct |
55 |
Correct |
3 ms |
13148 KB |
Output is correct |
56 |
Correct |
6 ms |
15448 KB |
Output is correct |
57 |
Correct |
4 ms |
15456 KB |
Output is correct |
58 |
Correct |
4 ms |
15308 KB |
Output is correct |
59 |
Correct |
4 ms |
15448 KB |
Output is correct |
60 |
Correct |
5 ms |
15448 KB |
Output is correct |
61 |
Correct |
4 ms |
15452 KB |
Output is correct |
62 |
Correct |
4 ms |
15452 KB |
Output is correct |
63 |
Correct |
4 ms |
15448 KB |
Output is correct |
64 |
Correct |
5 ms |
15452 KB |
Output is correct |
65 |
Correct |
4 ms |
15452 KB |
Output is correct |
66 |
Correct |
4 ms |
15452 KB |
Output is correct |
67 |
Correct |
118 ms |
37012 KB |
Output is correct |
68 |
Correct |
123 ms |
35892 KB |
Output is correct |
69 |
Correct |
160 ms |
38928 KB |
Output is correct |
70 |
Correct |
163 ms |
39512 KB |
Output is correct |
71 |
Correct |
154 ms |
39608 KB |
Output is correct |
72 |
Correct |
142 ms |
37300 KB |
Output is correct |
73 |
Correct |
130 ms |
40024 KB |
Output is correct |
74 |
Correct |
112 ms |
35488 KB |
Output is correct |
75 |
Correct |
142 ms |
37052 KB |
Output is correct |
76 |
Correct |
123 ms |
35252 KB |
Output is correct |
77 |
Correct |
113 ms |
35932 KB |
Output is correct |
78 |
Correct |
116 ms |
35836 KB |
Output is correct |
79 |
Correct |
106 ms |
37232 KB |
Output is correct |
80 |
Correct |
99 ms |
36452 KB |
Output is correct |
81 |
Correct |
186 ms |
39608 KB |
Output is correct |
82 |
Correct |
182 ms |
39576 KB |
Output is correct |
83 |
Correct |
141 ms |
37308 KB |
Output is correct |
84 |
Correct |
103 ms |
35936 KB |
Output is correct |
85 |
Correct |
224 ms |
39432 KB |
Output is correct |
86 |
Correct |
120 ms |
37300 KB |
Output is correct |
87 |
Correct |
170 ms |
38092 KB |
Output is correct |
88 |
Correct |
99 ms |
36532 KB |
Output is correct |
89 |
Correct |
135 ms |
35532 KB |
Output is correct |
90 |
Correct |
189 ms |
37360 KB |
Output is correct |
91 |
Correct |
162 ms |
37676 KB |
Output is correct |
92 |
Correct |
198 ms |
38760 KB |
Output is correct |
93 |
Correct |
204 ms |
40116 KB |
Output is correct |
94 |
Correct |
133 ms |
37556 KB |
Output is correct |
95 |
Correct |
112 ms |
38480 KB |
Output is correct |
96 |
Correct |
82 ms |
36088 KB |
Output is correct |
97 |
Correct |
79 ms |
27396 KB |
Output is correct |
98 |
Correct |
147 ms |
40588 KB |
Output is correct |
99 |
Correct |
161 ms |
35764 KB |
Output is correct |
100 |
Correct |
33 ms |
19580 KB |
Output is correct |
101 |
Correct |
157 ms |
38072 KB |
Output is correct |
102 |
Correct |
151 ms |
35164 KB |
Output is correct |
103 |
Correct |
163 ms |
33972 KB |
Output is correct |
104 |
Correct |
147 ms |
36720 KB |
Output is correct |