#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 4e5 + 2;
int a[maxn], dsu[maxn];
int64 sum[maxn];
vector <pair <int, int> > ad [maxn];
vector <int> comp [maxn];
int rs [maxn];
int dad (int x) {
return dsu[x] = (x == dsu[x] ? x: dad(dsu[x]));
}
int main() {
int n,m;
cin >> n >> m;
vector <pair <int, int> > v;
for (int i = 1; i <= n; i++){
cin >> a[i];
dsu[i] = i;
sum[i] = a[i];
comp[i].push_back(i);
v.push_back({a[i], i});
}
for (int i = 1; i <= m; i++){
int x,y;
cin >> x >> y;
ad[x].push_back({a[y], y});
ad[y].push_back({a[x], x});
}
set <pair <int, int> > s;
sort(v.begin(), v.end());
for (auto [val, x]: v) {
sort(ad[x].rbegin(), ad[x].rend());
while (!ad[x].empty() && ad[x].back().first <= val) {
int y = ad[x].back().second;
int p1 = dad(x), p2 = dad(y);
// cout << x << " " << y << p1 << " " << p2 << "\n";
if (val > sum[p2]) comp[p2].clear();
if (p1 != p2) {
dsu[p2] = p1;
sum[p1] += sum[p2];
if (comp[p1].size() < comp[p2].size()) swap(comp[p1], comp[p2]);
for (int i: comp[p2]) comp[p1].push_back(i);
}
ad[x].pop_back();
}
}
map <int, int> dd;
for (int i = 1; i <= n; i++){
if (!dd.count(dad(i))) {
dd[i] = 1;
for (int j: comp[dad(i)]) rs[j] = 1;
}
}
for (int i = 1; i <= n; i++) cout << rs[i] << "";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19064 KB |
Output is correct |
3 |
Correct |
10 ms |
19100 KB |
Output is correct |
4 |
Correct |
14 ms |
19284 KB |
Output is correct |
5 |
Correct |
14 ms |
19360 KB |
Output is correct |
6 |
Correct |
18 ms |
19360 KB |
Output is correct |
7 |
Correct |
13 ms |
19284 KB |
Output is correct |
8 |
Correct |
15 ms |
19284 KB |
Output is correct |
9 |
Correct |
13 ms |
19412 KB |
Output is correct |
10 |
Correct |
16 ms |
19368 KB |
Output is correct |
11 |
Correct |
14 ms |
19372 KB |
Output is correct |
12 |
Correct |
12 ms |
19372 KB |
Output is correct |
13 |
Correct |
12 ms |
19244 KB |
Output is correct |
14 |
Correct |
12 ms |
19236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19112 KB |
Output is correct |
2 |
Correct |
10 ms |
19080 KB |
Output is correct |
3 |
Correct |
302 ms |
42004 KB |
Output is correct |
4 |
Correct |
252 ms |
40900 KB |
Output is correct |
5 |
Correct |
315 ms |
42292 KB |
Output is correct |
6 |
Correct |
316 ms |
43500 KB |
Output is correct |
7 |
Correct |
314 ms |
44288 KB |
Output is correct |
8 |
Correct |
354 ms |
42856 KB |
Output is correct |
9 |
Correct |
289 ms |
46580 KB |
Output is correct |
10 |
Correct |
258 ms |
41092 KB |
Output is correct |
11 |
Correct |
267 ms |
43500 KB |
Output is correct |
12 |
Correct |
307 ms |
40744 KB |
Output is correct |
13 |
Correct |
277 ms |
39736 KB |
Output is correct |
14 |
Correct |
260 ms |
40676 KB |
Output is correct |
15 |
Correct |
299 ms |
42364 KB |
Output is correct |
16 |
Correct |
221 ms |
41536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Execution timed out |
1057 ms |
43920 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19032 KB |
Output is correct |
2 |
Execution timed out |
1071 ms |
43004 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19064 KB |
Output is correct |
3 |
Correct |
10 ms |
19100 KB |
Output is correct |
4 |
Correct |
14 ms |
19284 KB |
Output is correct |
5 |
Correct |
14 ms |
19360 KB |
Output is correct |
6 |
Correct |
18 ms |
19360 KB |
Output is correct |
7 |
Correct |
13 ms |
19284 KB |
Output is correct |
8 |
Correct |
15 ms |
19284 KB |
Output is correct |
9 |
Correct |
13 ms |
19412 KB |
Output is correct |
10 |
Correct |
16 ms |
19368 KB |
Output is correct |
11 |
Correct |
14 ms |
19372 KB |
Output is correct |
12 |
Correct |
12 ms |
19372 KB |
Output is correct |
13 |
Correct |
12 ms |
19244 KB |
Output is correct |
14 |
Correct |
12 ms |
19236 KB |
Output is correct |
15 |
Correct |
9 ms |
19112 KB |
Output is correct |
16 |
Correct |
10 ms |
19080 KB |
Output is correct |
17 |
Correct |
302 ms |
42004 KB |
Output is correct |
18 |
Correct |
252 ms |
40900 KB |
Output is correct |
19 |
Correct |
315 ms |
42292 KB |
Output is correct |
20 |
Correct |
316 ms |
43500 KB |
Output is correct |
21 |
Correct |
314 ms |
44288 KB |
Output is correct |
22 |
Correct |
354 ms |
42856 KB |
Output is correct |
23 |
Correct |
289 ms |
46580 KB |
Output is correct |
24 |
Correct |
258 ms |
41092 KB |
Output is correct |
25 |
Correct |
267 ms |
43500 KB |
Output is correct |
26 |
Correct |
307 ms |
40744 KB |
Output is correct |
27 |
Correct |
277 ms |
39736 KB |
Output is correct |
28 |
Correct |
260 ms |
40676 KB |
Output is correct |
29 |
Correct |
299 ms |
42364 KB |
Output is correct |
30 |
Correct |
221 ms |
41536 KB |
Output is correct |
31 |
Correct |
10 ms |
19028 KB |
Output is correct |
32 |
Execution timed out |
1057 ms |
43920 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |