#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct unionFind{
int par[200002], num[200002];
void init(int n){
for(int i=1; i<=n; i++) par[i] = num[i] = i;
}
int find(int x){
if(x==par[x]) return x;
return par[x] = find(par[x]);
}
void merge(int x, int y){
x = find(x), y = find(y);
par[x] = y;
}
} dsu;
struct segTree{
ll tree[1600002];
void init(int i, int l, int r){
tree[i] = 1e18;
if(l==r) return;
int m = (l+r)>>1;
init(i*2, l, m), init(i*2+1, m+1, r);
}
void update(int i, int l, int r, int x, ll v){
if(l==r){
tree[i] = min(tree[i], v);
return;
}
int m = (l+r)>>1;
if(x<=m) update(i*2, l, m, x, v);
else update(i*2+1, m+1, r, x, v);
tree[i] = min(tree[i*2], tree[i*2+1]);
}
ll query(int i, int l, int r, int s, int e){
if(r<s || e<l) return 1e18;
if(s<=l && r<=e) return tree[i];
int m = (l+r)>>1;
return min(query(i*2, l, m, s, e), query(i*2+1, m+1, r, s, e));
}
} tree;
int n, m;
ll arr[400002];
bool ans[200002];
vector<int> link[200002];
vector<pair<ll, int> > arrVec;
void solve();
int main(){
scanf("%d %d", &n, &m);
for(int i=1; i<=n; i++){
scanf("%lld", &arr[i]);
arrVec.push_back(make_pair(arr[i], i));
}
sort(arrVec.begin(), arrVec.end());
for(int i=1; i<=m; i++){
int x, y;
scanf("%d %d", &x, &y);
link[x].push_back(y);
link[y].push_back(x);
}
solve();
for(int i=1; i<=n; i++) printf("%d", ans[i]);
}
int nodeCnt, root;
vector<int> child[400002];
int par[400002], in[400002], out[400002], inCnt;
ll sum[400002];
int sps[400002][20];
void makeTree(){
nodeCnt = n;
dsu.init(n);
for(pair<ll, int> p: arrVec){
int x = p.second;
for(auto y: link[x]){
if(arr[y] > p.first || dsu.find(x) == dsu.find(y)) continue;
int a = dsu.num[dsu.find(x)], b = dsu.num[dsu.find(y)], c = ++nodeCnt;
par[a] = par[b] = c;
child[c].push_back(a), child[c].push_back(b);
dsu.merge(x, y);
dsu.num[dsu.find(x)] = c;
arr[c] = p.first;
}
}
root = nodeCnt;
assert(root == n+n-1);
for(int i=1; i<=nodeCnt; i++) sps[i][0] = par[i];
for(int d=1; d<20; d++) for(int i=1; i<=nodeCnt; i++) sps[i][d] = sps[sps[i][d-1]][d-1];
}
void traverse(int x=root){
in[x] = ++inCnt;
if(x <= n) sum[x] = arr[x];
for(auto y: child[x]){
traverse(y);
sum[x] += sum[y];
}
out[x] = inCnt;
}
void makeGood(int x){
ans[x] = 1;
for(auto y: link[x]){
tree.update(1, 1, nodeCnt, in[y], arr[x]);
}
}
void finalSolve(){
tree.init(1, 1, nodeCnt);
for(int s=(int)arrVec.size()-1; s>=0; s--){
int e = s;
while(e && arrVec[e-1].first == arrVec[s].first) e--;
ll w = arrVec[s].first;
/// [e, s] ���� ��� �Ϸ�, w�� �� �������� ����ġ
for(int i=e; i<=s; i++){
int x = arrVec[i].second; /// x�� good point���� ����
if(s==(int)arrVec.size()-1){ /// ���� ����ġ ū ���� �ٷ� �հ�
makeGood(x); continue;
}
int top = x;
for(int d=19; d>=0; d--) if(sps[top][d] && arr[sps[top][d]] <= w) top = sps[top][d];
ll tq = tree.query(1, 1, nodeCnt, in[top], out[top]);
if(tq <= sum[top]) makeGood(x);
}
s=e;
}
}
void solve(){
makeTree();
traverse();
finalSolve();
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
island.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | scanf("%lld", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~~~
island.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14452 KB |
Output is correct |
4 |
Correct |
10 ms |
15060 KB |
Output is correct |
5 |
Correct |
13 ms |
15060 KB |
Output is correct |
6 |
Correct |
12 ms |
14936 KB |
Output is correct |
7 |
Correct |
12 ms |
14932 KB |
Output is correct |
8 |
Correct |
12 ms |
14932 KB |
Output is correct |
9 |
Correct |
11 ms |
15188 KB |
Output is correct |
10 |
Correct |
10 ms |
15124 KB |
Output is correct |
11 |
Correct |
10 ms |
15060 KB |
Output is correct |
12 |
Correct |
10 ms |
15044 KB |
Output is correct |
13 |
Correct |
9 ms |
15208 KB |
Output is correct |
14 |
Correct |
10 ms |
15060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14396 KB |
Output is correct |
3 |
Correct |
373 ms |
87256 KB |
Output is correct |
4 |
Correct |
290 ms |
90672 KB |
Output is correct |
5 |
Correct |
470 ms |
80788 KB |
Output is correct |
6 |
Correct |
483 ms |
82328 KB |
Output is correct |
7 |
Correct |
524 ms |
82504 KB |
Output is correct |
8 |
Correct |
542 ms |
91936 KB |
Output is correct |
9 |
Correct |
335 ms |
82340 KB |
Output is correct |
10 |
Correct |
480 ms |
92416 KB |
Output is correct |
11 |
Correct |
381 ms |
92680 KB |
Output is correct |
12 |
Correct |
475 ms |
84340 KB |
Output is correct |
13 |
Correct |
313 ms |
91620 KB |
Output is correct |
14 |
Correct |
295 ms |
90752 KB |
Output is correct |
15 |
Correct |
380 ms |
91852 KB |
Output is correct |
16 |
Correct |
310 ms |
91136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14452 KB |
Output is correct |
2 |
Correct |
521 ms |
82052 KB |
Output is correct |
3 |
Correct |
544 ms |
82424 KB |
Output is correct |
4 |
Correct |
336 ms |
91808 KB |
Output is correct |
5 |
Correct |
305 ms |
88620 KB |
Output is correct |
6 |
Correct |
520 ms |
82464 KB |
Output is correct |
7 |
Correct |
395 ms |
91952 KB |
Output is correct |
8 |
Correct |
384 ms |
91948 KB |
Output is correct |
9 |
Correct |
282 ms |
91124 KB |
Output is correct |
10 |
Correct |
341 ms |
89528 KB |
Output is correct |
11 |
Correct |
345 ms |
84612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14392 KB |
Output is correct |
2 |
Correct |
560 ms |
82988 KB |
Output is correct |
3 |
Correct |
534 ms |
82480 KB |
Output is correct |
4 |
Correct |
556 ms |
82640 KB |
Output is correct |
5 |
Correct |
457 ms |
82652 KB |
Output is correct |
6 |
Correct |
425 ms |
80836 KB |
Output is correct |
7 |
Correct |
395 ms |
92644 KB |
Output is correct |
8 |
Correct |
261 ms |
91656 KB |
Output is correct |
9 |
Correct |
267 ms |
49736 KB |
Output is correct |
10 |
Correct |
361 ms |
82312 KB |
Output is correct |
11 |
Correct |
360 ms |
84616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14452 KB |
Output is correct |
4 |
Correct |
10 ms |
15060 KB |
Output is correct |
5 |
Correct |
13 ms |
15060 KB |
Output is correct |
6 |
Correct |
12 ms |
14936 KB |
Output is correct |
7 |
Correct |
12 ms |
14932 KB |
Output is correct |
8 |
Correct |
12 ms |
14932 KB |
Output is correct |
9 |
Correct |
11 ms |
15188 KB |
Output is correct |
10 |
Correct |
10 ms |
15124 KB |
Output is correct |
11 |
Correct |
10 ms |
15060 KB |
Output is correct |
12 |
Correct |
10 ms |
15044 KB |
Output is correct |
13 |
Correct |
9 ms |
15208 KB |
Output is correct |
14 |
Correct |
10 ms |
15060 KB |
Output is correct |
15 |
Correct |
7 ms |
14420 KB |
Output is correct |
16 |
Correct |
7 ms |
14396 KB |
Output is correct |
17 |
Correct |
373 ms |
87256 KB |
Output is correct |
18 |
Correct |
290 ms |
90672 KB |
Output is correct |
19 |
Correct |
470 ms |
80788 KB |
Output is correct |
20 |
Correct |
483 ms |
82328 KB |
Output is correct |
21 |
Correct |
524 ms |
82504 KB |
Output is correct |
22 |
Correct |
542 ms |
91936 KB |
Output is correct |
23 |
Correct |
335 ms |
82340 KB |
Output is correct |
24 |
Correct |
480 ms |
92416 KB |
Output is correct |
25 |
Correct |
381 ms |
92680 KB |
Output is correct |
26 |
Correct |
475 ms |
84340 KB |
Output is correct |
27 |
Correct |
313 ms |
91620 KB |
Output is correct |
28 |
Correct |
295 ms |
90752 KB |
Output is correct |
29 |
Correct |
380 ms |
91852 KB |
Output is correct |
30 |
Correct |
310 ms |
91136 KB |
Output is correct |
31 |
Correct |
8 ms |
14452 KB |
Output is correct |
32 |
Correct |
521 ms |
82052 KB |
Output is correct |
33 |
Correct |
544 ms |
82424 KB |
Output is correct |
34 |
Correct |
336 ms |
91808 KB |
Output is correct |
35 |
Correct |
305 ms |
88620 KB |
Output is correct |
36 |
Correct |
520 ms |
82464 KB |
Output is correct |
37 |
Correct |
395 ms |
91952 KB |
Output is correct |
38 |
Correct |
384 ms |
91948 KB |
Output is correct |
39 |
Correct |
282 ms |
91124 KB |
Output is correct |
40 |
Correct |
341 ms |
89528 KB |
Output is correct |
41 |
Correct |
345 ms |
84612 KB |
Output is correct |
42 |
Correct |
9 ms |
14392 KB |
Output is correct |
43 |
Correct |
560 ms |
82988 KB |
Output is correct |
44 |
Correct |
534 ms |
82480 KB |
Output is correct |
45 |
Correct |
556 ms |
82640 KB |
Output is correct |
46 |
Correct |
457 ms |
82652 KB |
Output is correct |
47 |
Correct |
425 ms |
80836 KB |
Output is correct |
48 |
Correct |
395 ms |
92644 KB |
Output is correct |
49 |
Correct |
261 ms |
91656 KB |
Output is correct |
50 |
Correct |
267 ms |
49736 KB |
Output is correct |
51 |
Correct |
361 ms |
82312 KB |
Output is correct |
52 |
Correct |
360 ms |
84616 KB |
Output is correct |
53 |
Correct |
8 ms |
14420 KB |
Output is correct |
54 |
Correct |
8 ms |
14344 KB |
Output is correct |
55 |
Correct |
7 ms |
14420 KB |
Output is correct |
56 |
Correct |
12 ms |
14948 KB |
Output is correct |
57 |
Correct |
10 ms |
15048 KB |
Output is correct |
58 |
Correct |
10 ms |
14932 KB |
Output is correct |
59 |
Correct |
10 ms |
14932 KB |
Output is correct |
60 |
Correct |
11 ms |
14956 KB |
Output is correct |
61 |
Correct |
10 ms |
15192 KB |
Output is correct |
62 |
Correct |
10 ms |
15056 KB |
Output is correct |
63 |
Correct |
11 ms |
15060 KB |
Output is correct |
64 |
Correct |
10 ms |
15060 KB |
Output is correct |
65 |
Correct |
9 ms |
15188 KB |
Output is correct |
66 |
Correct |
10 ms |
15088 KB |
Output is correct |
67 |
Correct |
349 ms |
87340 KB |
Output is correct |
68 |
Correct |
331 ms |
90708 KB |
Output is correct |
69 |
Correct |
435 ms |
80740 KB |
Output is correct |
70 |
Correct |
504 ms |
82488 KB |
Output is correct |
71 |
Correct |
499 ms |
82644 KB |
Output is correct |
72 |
Correct |
450 ms |
91820 KB |
Output is correct |
73 |
Correct |
385 ms |
82276 KB |
Output is correct |
74 |
Correct |
361 ms |
92488 KB |
Output is correct |
75 |
Correct |
370 ms |
92604 KB |
Output is correct |
76 |
Correct |
411 ms |
84104 KB |
Output is correct |
77 |
Correct |
321 ms |
91636 KB |
Output is correct |
78 |
Correct |
288 ms |
90748 KB |
Output is correct |
79 |
Correct |
407 ms |
91832 KB |
Output is correct |
80 |
Correct |
277 ms |
91120 KB |
Output is correct |
81 |
Correct |
548 ms |
82144 KB |
Output is correct |
82 |
Correct |
540 ms |
82444 KB |
Output is correct |
83 |
Correct |
352 ms |
91852 KB |
Output is correct |
84 |
Correct |
297 ms |
88676 KB |
Output is correct |
85 |
Correct |
530 ms |
82460 KB |
Output is correct |
86 |
Correct |
406 ms |
91816 KB |
Output is correct |
87 |
Correct |
382 ms |
91792 KB |
Output is correct |
88 |
Correct |
366 ms |
89428 KB |
Output is correct |
89 |
Correct |
339 ms |
84616 KB |
Output is correct |
90 |
Correct |
533 ms |
83000 KB |
Output is correct |
91 |
Correct |
572 ms |
82408 KB |
Output is correct |
92 |
Correct |
630 ms |
82532 KB |
Output is correct |
93 |
Correct |
474 ms |
82484 KB |
Output is correct |
94 |
Correct |
469 ms |
80828 KB |
Output is correct |
95 |
Correct |
482 ms |
92664 KB |
Output is correct |
96 |
Correct |
297 ms |
91756 KB |
Output is correct |
97 |
Correct |
283 ms |
49652 KB |
Output is correct |
98 |
Correct |
410 ms |
82360 KB |
Output is correct |
99 |
Correct |
394 ms |
84684 KB |
Output is correct |
100 |
Correct |
97 ms |
17996 KB |
Output is correct |
101 |
Correct |
605 ms |
82604 KB |
Output is correct |
102 |
Correct |
434 ms |
71960 KB |
Output is correct |
103 |
Correct |
571 ms |
75908 KB |
Output is correct |
104 |
Correct |
643 ms |
82696 KB |
Output is correct |