/*
* File created on 07/19/2022 at 15:02:09.
* Link to problem:
* Description:
* Time complexity: O()
* Space complexity: O()
* Status: ---
* Copyright: Ⓒ 2022 Francois Vogel
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pii pair<int, int>
#define f first
#define s second
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define size(x) (int)((x).size())
#define pb push_back
#define ins insert
#define cls clear
#define int ll
#define ll long long
#define ld long double
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int siz = 2e5+40;
int par [siz];
int sum [siz];
vi el [siz];
int gp(int x) {
if (par[x] == x) return x;
return par[x] = gp(par[x]);
}
void merge(int x, int y) {
x = gp(x);
y = gp(y);
if (x == y) return;
if (size(el[x]) < size(el[y])) swap(x, y);
par[y] = x;
sum[x] += sum[y];
for (int i : el[y]) el[x].pb(i);
}
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, nbE;
cin >> n >> nbE;
int val [n];
for (int i = 0; i < n; i++) {
cin >> val[i];
}
vi graph [n];
for (int i = 0; i < nbE; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
graph[a].pb(b);
graph[b].pb(a);
}
vector<pii> sorted;
for (int i = 0; i < n; i++) {
sorted.pb({val[i], i});
}
sort(all(sorted));
bool proc [n];
for (int i = 0; i < n; i++) {
proc[i] = false;
par[i] = i;
sum[i] = val[i];
el[i] = {i};
}
int res [n];
for (int i = 0; i < n; i++) {
res[i] = 1;
}
for (pii i : sorted) {
proc[i.s] = true;
for (int j : graph[i.s]) if (proc[j]) {
int x = gp(j);
if (sum[x] < i.f) {
for (int k : el[x]) {
res[k] = 0;
}
el[x].cls();
}
}
for (int j : graph[i.s]) if (proc[j]) {
merge(i.s, j);
}
}
for (int i : res) {
cout << i;
}
cout.flush();
int d = 0;
d++;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
4 ms |
5272 KB |
Output is correct |
5 |
Correct |
4 ms |
5332 KB |
Output is correct |
6 |
Correct |
4 ms |
5204 KB |
Output is correct |
7 |
Correct |
4 ms |
5304 KB |
Output is correct |
8 |
Correct |
5 ms |
5204 KB |
Output is correct |
9 |
Correct |
5 ms |
5332 KB |
Output is correct |
10 |
Correct |
5 ms |
5332 KB |
Output is correct |
11 |
Correct |
4 ms |
5332 KB |
Output is correct |
12 |
Correct |
4 ms |
5332 KB |
Output is correct |
13 |
Correct |
4 ms |
5332 KB |
Output is correct |
14 |
Correct |
4 ms |
5280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
158 ms |
38084 KB |
Output is correct |
4 |
Correct |
156 ms |
38068 KB |
Output is correct |
5 |
Correct |
244 ms |
39908 KB |
Output is correct |
6 |
Correct |
195 ms |
41604 KB |
Output is correct |
7 |
Correct |
202 ms |
42448 KB |
Output is correct |
8 |
Correct |
223 ms |
39296 KB |
Output is correct |
9 |
Correct |
174 ms |
45092 KB |
Output is correct |
10 |
Correct |
146 ms |
36592 KB |
Output is correct |
11 |
Correct |
174 ms |
40016 KB |
Output is correct |
12 |
Correct |
191 ms |
37300 KB |
Output is correct |
13 |
Correct |
145 ms |
36884 KB |
Output is correct |
14 |
Correct |
160 ms |
37864 KB |
Output is correct |
15 |
Correct |
153 ms |
39352 KB |
Output is correct |
16 |
Correct |
99 ms |
38012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
246 ms |
43444 KB |
Output is correct |
3 |
Correct |
243 ms |
42956 KB |
Output is correct |
4 |
Correct |
203 ms |
39700 KB |
Output is correct |
5 |
Correct |
167 ms |
37748 KB |
Output is correct |
6 |
Correct |
233 ms |
43320 KB |
Output is correct |
7 |
Correct |
177 ms |
38884 KB |
Output is correct |
8 |
Correct |
198 ms |
38868 KB |
Output is correct |
9 |
Correct |
99 ms |
37816 KB |
Output is correct |
10 |
Correct |
179 ms |
35496 KB |
Output is correct |
11 |
Correct |
182 ms |
38072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
236 ms |
39540 KB |
Output is correct |
3 |
Correct |
239 ms |
40416 KB |
Output is correct |
4 |
Correct |
295 ms |
40948 KB |
Output is correct |
5 |
Correct |
221 ms |
46444 KB |
Output is correct |
6 |
Correct |
198 ms |
40552 KB |
Output is correct |
7 |
Correct |
149 ms |
38764 KB |
Output is correct |
8 |
Correct |
100 ms |
39308 KB |
Output is correct |
9 |
Correct |
128 ms |
23924 KB |
Output is correct |
10 |
Correct |
220 ms |
45360 KB |
Output is correct |
11 |
Correct |
169 ms |
36588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
4 ms |
5272 KB |
Output is correct |
5 |
Correct |
4 ms |
5332 KB |
Output is correct |
6 |
Correct |
4 ms |
5204 KB |
Output is correct |
7 |
Correct |
4 ms |
5304 KB |
Output is correct |
8 |
Correct |
5 ms |
5204 KB |
Output is correct |
9 |
Correct |
5 ms |
5332 KB |
Output is correct |
10 |
Correct |
5 ms |
5332 KB |
Output is correct |
11 |
Correct |
4 ms |
5332 KB |
Output is correct |
12 |
Correct |
4 ms |
5332 KB |
Output is correct |
13 |
Correct |
4 ms |
5332 KB |
Output is correct |
14 |
Correct |
4 ms |
5280 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
158 ms |
38084 KB |
Output is correct |
18 |
Correct |
156 ms |
38068 KB |
Output is correct |
19 |
Correct |
244 ms |
39908 KB |
Output is correct |
20 |
Correct |
195 ms |
41604 KB |
Output is correct |
21 |
Correct |
202 ms |
42448 KB |
Output is correct |
22 |
Correct |
223 ms |
39296 KB |
Output is correct |
23 |
Correct |
174 ms |
45092 KB |
Output is correct |
24 |
Correct |
146 ms |
36592 KB |
Output is correct |
25 |
Correct |
174 ms |
40016 KB |
Output is correct |
26 |
Correct |
191 ms |
37300 KB |
Output is correct |
27 |
Correct |
145 ms |
36884 KB |
Output is correct |
28 |
Correct |
160 ms |
37864 KB |
Output is correct |
29 |
Correct |
153 ms |
39352 KB |
Output is correct |
30 |
Correct |
99 ms |
38012 KB |
Output is correct |
31 |
Correct |
3 ms |
4948 KB |
Output is correct |
32 |
Correct |
246 ms |
43444 KB |
Output is correct |
33 |
Correct |
243 ms |
42956 KB |
Output is correct |
34 |
Correct |
203 ms |
39700 KB |
Output is correct |
35 |
Correct |
167 ms |
37748 KB |
Output is correct |
36 |
Correct |
233 ms |
43320 KB |
Output is correct |
37 |
Correct |
177 ms |
38884 KB |
Output is correct |
38 |
Correct |
198 ms |
38868 KB |
Output is correct |
39 |
Correct |
99 ms |
37816 KB |
Output is correct |
40 |
Correct |
179 ms |
35496 KB |
Output is correct |
41 |
Correct |
182 ms |
38072 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
236 ms |
39540 KB |
Output is correct |
44 |
Correct |
239 ms |
40416 KB |
Output is correct |
45 |
Correct |
295 ms |
40948 KB |
Output is correct |
46 |
Correct |
221 ms |
46444 KB |
Output is correct |
47 |
Correct |
198 ms |
40552 KB |
Output is correct |
48 |
Correct |
149 ms |
38764 KB |
Output is correct |
49 |
Correct |
100 ms |
39308 KB |
Output is correct |
50 |
Correct |
128 ms |
23924 KB |
Output is correct |
51 |
Correct |
220 ms |
45360 KB |
Output is correct |
52 |
Correct |
169 ms |
36588 KB |
Output is correct |
53 |
Correct |
3 ms |
5028 KB |
Output is correct |
54 |
Correct |
3 ms |
4948 KB |
Output is correct |
55 |
Correct |
3 ms |
4932 KB |
Output is correct |
56 |
Correct |
4 ms |
5204 KB |
Output is correct |
57 |
Correct |
4 ms |
5332 KB |
Output is correct |
58 |
Correct |
5 ms |
5296 KB |
Output is correct |
59 |
Correct |
4 ms |
5300 KB |
Output is correct |
60 |
Correct |
4 ms |
5168 KB |
Output is correct |
61 |
Correct |
4 ms |
5300 KB |
Output is correct |
62 |
Correct |
4 ms |
5320 KB |
Output is correct |
63 |
Correct |
5 ms |
5332 KB |
Output is correct |
64 |
Correct |
4 ms |
5332 KB |
Output is correct |
65 |
Correct |
4 ms |
5300 KB |
Output is correct |
66 |
Correct |
4 ms |
5332 KB |
Output is correct |
67 |
Correct |
181 ms |
38756 KB |
Output is correct |
68 |
Correct |
162 ms |
38324 KB |
Output is correct |
69 |
Correct |
188 ms |
39476 KB |
Output is correct |
70 |
Correct |
196 ms |
41716 KB |
Output is correct |
71 |
Correct |
222 ms |
41176 KB |
Output is correct |
72 |
Correct |
164 ms |
38916 KB |
Output is correct |
73 |
Correct |
207 ms |
45152 KB |
Output is correct |
74 |
Correct |
167 ms |
34780 KB |
Output is correct |
75 |
Correct |
140 ms |
38704 KB |
Output is correct |
76 |
Correct |
184 ms |
36692 KB |
Output is correct |
77 |
Correct |
174 ms |
36748 KB |
Output is correct |
78 |
Correct |
143 ms |
36748 KB |
Output is correct |
79 |
Correct |
150 ms |
38040 KB |
Output is correct |
80 |
Correct |
107 ms |
38768 KB |
Output is correct |
81 |
Correct |
237 ms |
42320 KB |
Output is correct |
82 |
Correct |
242 ms |
43408 KB |
Output is correct |
83 |
Correct |
179 ms |
35712 KB |
Output is correct |
84 |
Correct |
143 ms |
37472 KB |
Output is correct |
85 |
Correct |
225 ms |
44484 KB |
Output is correct |
86 |
Correct |
171 ms |
39972 KB |
Output is correct |
87 |
Correct |
164 ms |
39872 KB |
Output is correct |
88 |
Correct |
164 ms |
34812 KB |
Output is correct |
89 |
Correct |
163 ms |
35376 KB |
Output is correct |
90 |
Correct |
242 ms |
39128 KB |
Output is correct |
91 |
Correct |
248 ms |
41704 KB |
Output is correct |
92 |
Correct |
258 ms |
44056 KB |
Output is correct |
93 |
Correct |
228 ms |
45576 KB |
Output is correct |
94 |
Correct |
201 ms |
40768 KB |
Output is correct |
95 |
Correct |
145 ms |
40732 KB |
Output is correct |
96 |
Correct |
100 ms |
38928 KB |
Output is correct |
97 |
Correct |
120 ms |
24344 KB |
Output is correct |
98 |
Correct |
241 ms |
46760 KB |
Output is correct |
99 |
Correct |
175 ms |
38024 KB |
Output is correct |
100 |
Correct |
44 ms |
11540 KB |
Output is correct |
101 |
Correct |
261 ms |
42316 KB |
Output is correct |
102 |
Correct |
187 ms |
34476 KB |
Output is correct |
103 |
Correct |
206 ms |
31156 KB |
Output is correct |
104 |
Correct |
264 ms |
36016 KB |
Output is correct |