#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define st first
#define nd second
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
const int MAXN = 200009;
int tab[MAXN];
bool ans[MAXN];
map<int, vector<int>> M;
map<int, vector<pii>> edges;
int dependency[MAXN];
int p[MAXN];
int sum[MAXN];
set<pii> S[MAXN];
vector<int> cost;
int Find(int x) {
return p[x]==x?x:p[x]=Find(p[x]);
}
void Union(int x, int y) {
int X = Find(x);
int Y = Find(y);
if(X==Y) return;
if(sz(S[X])<sz(S[Y])) swap(X, Y);
p[Y] = X;
sum[X] += sum[Y];
sum[X] = min(sum[X], 1000000009);
for(pii val:S[Y]) {
S[X].insert(val);
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
int Max = 0;
for(int i=1;i<=n;i++) {
cin >> tab[i];
M[tab[i]].pb(i);
Max = max(Max, tab[i]);
p[i] = i;
sum[i] = tab[i];
}
for(int i=0;i<m;i++) {
int a, b;
cin >> a >> b;
S[a].insert({tab[b], b});
S[b].insert({tab[a], a});
edges[max(tab[a], tab[b])].pb({a, b});
}
for(auto &x:M) {
for(pii y:edges[x.st]) {
Union(y.st, y.nd);
}
for(int y:x.nd) {
int Y = Find(y);
auto it = S[Y].upper_bound({sum[Y], 1e9});
if(it!=S[Y].begin()) {
it--;
dependency[y] = it->nd;
}
}
}
for(int x:M[Max]) {
ans[x] = true;
}
M.erase(Max);
for(auto it = M.rbegin();it!=M.rend();it++) {
for(int y:(*it).nd) {
if(ans[dependency[y]]) {
ans[y] = true;
}
}
}
for(int i=1;i<=n;i++) {
cout << ans[i];
}
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
9 ms |
10456 KB |
Output is correct |
5 |
Correct |
9 ms |
10512 KB |
Output is correct |
6 |
Correct |
7 ms |
10196 KB |
Output is correct |
7 |
Correct |
8 ms |
10380 KB |
Output is correct |
8 |
Correct |
8 ms |
10324 KB |
Output is correct |
9 |
Correct |
6 ms |
10000 KB |
Output is correct |
10 |
Correct |
10 ms |
10708 KB |
Output is correct |
11 |
Correct |
10 ms |
10796 KB |
Output is correct |
12 |
Correct |
9 ms |
10708 KB |
Output is correct |
13 |
Correct |
7 ms |
10324 KB |
Output is correct |
14 |
Correct |
8 ms |
10196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9728 KB |
Output is correct |
3 |
Correct |
572 ms |
93096 KB |
Output is correct |
4 |
Correct |
583 ms |
92920 KB |
Output is correct |
5 |
Correct |
787 ms |
115780 KB |
Output is correct |
6 |
Correct |
737 ms |
111568 KB |
Output is correct |
7 |
Correct |
772 ms |
120472 KB |
Output is correct |
8 |
Correct |
551 ms |
82268 KB |
Output is correct |
9 |
Correct |
721 ms |
141496 KB |
Output is correct |
10 |
Correct |
391 ms |
64744 KB |
Output is correct |
11 |
Correct |
341 ms |
37516 KB |
Output is correct |
12 |
Correct |
662 ms |
84748 KB |
Output is correct |
13 |
Correct |
531 ms |
98572 KB |
Output is correct |
14 |
Correct |
604 ms |
97656 KB |
Output is correct |
15 |
Correct |
521 ms |
89736 KB |
Output is correct |
16 |
Correct |
325 ms |
88100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9732 KB |
Output is correct |
2 |
Correct |
922 ms |
136804 KB |
Output is correct |
3 |
Correct |
853 ms |
127324 KB |
Output is correct |
4 |
Correct |
532 ms |
98692 KB |
Output is correct |
5 |
Correct |
516 ms |
99776 KB |
Output is correct |
6 |
Correct |
932 ms |
135828 KB |
Output is correct |
7 |
Correct |
500 ms |
89696 KB |
Output is correct |
8 |
Correct |
514 ms |
89648 KB |
Output is correct |
9 |
Correct |
308 ms |
88140 KB |
Output is correct |
10 |
Correct |
581 ms |
117192 KB |
Output is correct |
11 |
Correct |
629 ms |
97540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
616 ms |
69240 KB |
Output is correct |
3 |
Correct |
612 ms |
73900 KB |
Output is correct |
4 |
Correct |
677 ms |
82188 KB |
Output is correct |
5 |
Correct |
554 ms |
76428 KB |
Output is correct |
6 |
Correct |
505 ms |
66416 KB |
Output is correct |
7 |
Correct |
303 ms |
38748 KB |
Output is correct |
8 |
Correct |
198 ms |
46960 KB |
Output is correct |
9 |
Correct |
488 ms |
45644 KB |
Output is correct |
10 |
Correct |
548 ms |
79812 KB |
Output is correct |
11 |
Correct |
596 ms |
96684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
9 ms |
10456 KB |
Output is correct |
5 |
Correct |
9 ms |
10512 KB |
Output is correct |
6 |
Correct |
7 ms |
10196 KB |
Output is correct |
7 |
Correct |
8 ms |
10380 KB |
Output is correct |
8 |
Correct |
8 ms |
10324 KB |
Output is correct |
9 |
Correct |
6 ms |
10000 KB |
Output is correct |
10 |
Correct |
10 ms |
10708 KB |
Output is correct |
11 |
Correct |
10 ms |
10796 KB |
Output is correct |
12 |
Correct |
9 ms |
10708 KB |
Output is correct |
13 |
Correct |
7 ms |
10324 KB |
Output is correct |
14 |
Correct |
8 ms |
10196 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9728 KB |
Output is correct |
17 |
Correct |
572 ms |
93096 KB |
Output is correct |
18 |
Correct |
583 ms |
92920 KB |
Output is correct |
19 |
Correct |
787 ms |
115780 KB |
Output is correct |
20 |
Correct |
737 ms |
111568 KB |
Output is correct |
21 |
Correct |
772 ms |
120472 KB |
Output is correct |
22 |
Correct |
551 ms |
82268 KB |
Output is correct |
23 |
Correct |
721 ms |
141496 KB |
Output is correct |
24 |
Correct |
391 ms |
64744 KB |
Output is correct |
25 |
Correct |
341 ms |
37516 KB |
Output is correct |
26 |
Correct |
662 ms |
84748 KB |
Output is correct |
27 |
Correct |
531 ms |
98572 KB |
Output is correct |
28 |
Correct |
604 ms |
97656 KB |
Output is correct |
29 |
Correct |
521 ms |
89736 KB |
Output is correct |
30 |
Correct |
325 ms |
88100 KB |
Output is correct |
31 |
Correct |
6 ms |
9732 KB |
Output is correct |
32 |
Correct |
922 ms |
136804 KB |
Output is correct |
33 |
Correct |
853 ms |
127324 KB |
Output is correct |
34 |
Correct |
532 ms |
98692 KB |
Output is correct |
35 |
Correct |
516 ms |
99776 KB |
Output is correct |
36 |
Correct |
932 ms |
135828 KB |
Output is correct |
37 |
Correct |
500 ms |
89696 KB |
Output is correct |
38 |
Correct |
514 ms |
89648 KB |
Output is correct |
39 |
Correct |
308 ms |
88140 KB |
Output is correct |
40 |
Correct |
581 ms |
117192 KB |
Output is correct |
41 |
Correct |
629 ms |
97540 KB |
Output is correct |
42 |
Correct |
5 ms |
9684 KB |
Output is correct |
43 |
Correct |
616 ms |
69240 KB |
Output is correct |
44 |
Correct |
612 ms |
73900 KB |
Output is correct |
45 |
Correct |
677 ms |
82188 KB |
Output is correct |
46 |
Correct |
554 ms |
76428 KB |
Output is correct |
47 |
Correct |
505 ms |
66416 KB |
Output is correct |
48 |
Correct |
303 ms |
38748 KB |
Output is correct |
49 |
Correct |
198 ms |
46960 KB |
Output is correct |
50 |
Correct |
488 ms |
45644 KB |
Output is correct |
51 |
Correct |
548 ms |
79812 KB |
Output is correct |
52 |
Correct |
596 ms |
96684 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
6 ms |
9728 KB |
Output is correct |
55 |
Correct |
5 ms |
9732 KB |
Output is correct |
56 |
Correct |
8 ms |
10492 KB |
Output is correct |
57 |
Correct |
9 ms |
10580 KB |
Output is correct |
58 |
Correct |
9 ms |
10148 KB |
Output is correct |
59 |
Correct |
9 ms |
10384 KB |
Output is correct |
60 |
Correct |
8 ms |
10324 KB |
Output is correct |
61 |
Correct |
6 ms |
10060 KB |
Output is correct |
62 |
Correct |
9 ms |
10628 KB |
Output is correct |
63 |
Correct |
10 ms |
10776 KB |
Output is correct |
64 |
Correct |
8 ms |
10708 KB |
Output is correct |
65 |
Correct |
7 ms |
10324 KB |
Output is correct |
66 |
Correct |
8 ms |
10196 KB |
Output is correct |
67 |
Correct |
524 ms |
93052 KB |
Output is correct |
68 |
Correct |
564 ms |
93032 KB |
Output is correct |
69 |
Correct |
744 ms |
115764 KB |
Output is correct |
70 |
Correct |
656 ms |
111604 KB |
Output is correct |
71 |
Correct |
710 ms |
120408 KB |
Output is correct |
72 |
Correct |
548 ms |
82220 KB |
Output is correct |
73 |
Correct |
695 ms |
141448 KB |
Output is correct |
74 |
Correct |
341 ms |
64840 KB |
Output is correct |
75 |
Correct |
310 ms |
37484 KB |
Output is correct |
76 |
Correct |
611 ms |
84728 KB |
Output is correct |
77 |
Correct |
505 ms |
98628 KB |
Output is correct |
78 |
Correct |
558 ms |
97664 KB |
Output is correct |
79 |
Correct |
523 ms |
89628 KB |
Output is correct |
80 |
Correct |
311 ms |
88168 KB |
Output is correct |
81 |
Correct |
866 ms |
136864 KB |
Output is correct |
82 |
Correct |
795 ms |
127312 KB |
Output is correct |
83 |
Correct |
508 ms |
98724 KB |
Output is correct |
84 |
Correct |
507 ms |
99820 KB |
Output is correct |
85 |
Correct |
898 ms |
135872 KB |
Output is correct |
86 |
Correct |
510 ms |
89664 KB |
Output is correct |
87 |
Correct |
515 ms |
89676 KB |
Output is correct |
88 |
Correct |
569 ms |
117308 KB |
Output is correct |
89 |
Correct |
614 ms |
97576 KB |
Output is correct |
90 |
Correct |
632 ms |
69076 KB |
Output is correct |
91 |
Correct |
638 ms |
73912 KB |
Output is correct |
92 |
Correct |
708 ms |
82216 KB |
Output is correct |
93 |
Correct |
515 ms |
76492 KB |
Output is correct |
94 |
Correct |
512 ms |
66600 KB |
Output is correct |
95 |
Correct |
274 ms |
38724 KB |
Output is correct |
96 |
Correct |
196 ms |
46860 KB |
Output is correct |
97 |
Correct |
483 ms |
45784 KB |
Output is correct |
98 |
Correct |
553 ms |
79684 KB |
Output is correct |
99 |
Correct |
567 ms |
96688 KB |
Output is correct |
100 |
Correct |
366 ms |
33820 KB |
Output is correct |
101 |
Correct |
849 ms |
108232 KB |
Output is correct |
102 |
Correct |
498 ms |
62184 KB |
Output is correct |
103 |
Correct |
750 ms |
81724 KB |
Output is correct |
104 |
Correct |
904 ms |
103900 KB |
Output is correct |