#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
long long root;
int s[200005];
int par[200005], ans[200005];
vector<tuple<int, int, int>> e1, e2;
vector<int> adj[200005];
long long sum[200005];
int fpar(int x) {
return x == par[x] ? x : par[x] = fpar(par[x]);
}
long long dfssum(int x) {
sum[x] = s[x];
for(int e:adj[x])
sum[x] += dfssum(e);
return sum[x];
}
void dfsans(int x, int parval = -1, bool parans = 1) {
ans[x] = (sum[x] >= parval && parans);
for(int e:adj[x])
dfsans(e, s[x], ans[x]);
}
int main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m; root = 1ll*n*(n+1)/2;
for(int i=1;i<=n;i++) {
cin >> s[i]; par[i] = i;
}
for(int i=1;i<=m;i++) {
cin >> a >> b;
e1.emplace_back(max(s[a], s[b]), a, b);
}
sort(e1.begin(), e1.end());
for(auto e:e1) {
//cout<<get<0>(e);
if(fpar(get<1>(e)) == fpar(get<2>(e))) continue;
e2.emplace_back(e); par[fpar(get<1>(e))] = fpar(get<2>(e));
}
for(int i=1;i<=n;i++) par[i]=i;
for(auto e:e2) {
if(s[get<1>(e)] == get<0>(e)) {
//cout << get<1>(e) << ' ' << get<2>(e) << ": ";
root -= fpar(get<2>(e)); //cout << "Neg " << fpar(get<2>(e));
adj[fpar(get<1>(e))].emplace_back(fpar(get<2>(e)));
par[fpar(get<2>(e))] = fpar(get<1>(e));
} else {
root -= fpar(get<1>(e)); //cout << "Neg " << fpar(get<1>(e));
adj[fpar(get<2>(e))].emplace_back(fpar(get<1>(e)));
par[fpar(get<1>(e))] = fpar(get<2>(e));
}
}
dfssum(root); dfsans(root);
for(int i=1;i<=n;i++) cout << ans[i];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5172 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 |
91 ms |
21820 KB |
Output is correct |
4 |
Correct |
85 ms |
21168 KB |
Output is correct |
5 |
Correct |
118 ms |
17320 KB |
Output is correct |
6 |
Correct |
104 ms |
17684 KB |
Output is correct |
7 |
Correct |
122 ms |
17764 KB |
Output is correct |
8 |
Correct |
101 ms |
21732 KB |
Output is correct |
9 |
Correct |
87 ms |
16896 KB |
Output is correct |
10 |
Correct |
70 ms |
15604 KB |
Output is correct |
11 |
Correct |
89 ms |
22000 KB |
Output is correct |
12 |
Correct |
98 ms |
17568 KB |
Output is correct |
13 |
Correct |
79 ms |
21676 KB |
Output is correct |
14 |
Correct |
81 ms |
21300 KB |
Output is correct |
15 |
Correct |
92 ms |
29464 KB |
Output is correct |
16 |
Correct |
70 ms |
29188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
106 ms |
17824 KB |
Output is correct |
3 |
Correct |
102 ms |
17908 KB |
Output is correct |
4 |
Correct |
93 ms |
21732 KB |
Output is correct |
5 |
Correct |
82 ms |
20152 KB |
Output is correct |
6 |
Correct |
103 ms |
17992 KB |
Output is correct |
7 |
Correct |
89 ms |
29432 KB |
Output is correct |
8 |
Correct |
89 ms |
29400 KB |
Output is correct |
9 |
Correct |
69 ms |
29144 KB |
Output is correct |
10 |
Correct |
82 ms |
21572 KB |
Output is correct |
11 |
Correct |
85 ms |
19248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
134 ms |
18060 KB |
Output is correct |
3 |
Correct |
117 ms |
17736 KB |
Output is correct |
4 |
Correct |
122 ms |
17636 KB |
Output is correct |
5 |
Correct |
106 ms |
16864 KB |
Output is correct |
6 |
Correct |
107 ms |
17108 KB |
Output is correct |
7 |
Correct |
83 ms |
21948 KB |
Output is correct |
8 |
Correct |
89 ms |
25572 KB |
Output is correct |
9 |
Correct |
77 ms |
13196 KB |
Output is correct |
10 |
Correct |
101 ms |
17028 KB |
Output is correct |
11 |
Correct |
85 ms |
19192 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 |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5172 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
91 ms |
21820 KB |
Output is correct |
18 |
Correct |
85 ms |
21168 KB |
Output is correct |
19 |
Correct |
118 ms |
17320 KB |
Output is correct |
20 |
Correct |
104 ms |
17684 KB |
Output is correct |
21 |
Correct |
122 ms |
17764 KB |
Output is correct |
22 |
Correct |
101 ms |
21732 KB |
Output is correct |
23 |
Correct |
87 ms |
16896 KB |
Output is correct |
24 |
Correct |
70 ms |
15604 KB |
Output is correct |
25 |
Correct |
89 ms |
22000 KB |
Output is correct |
26 |
Correct |
98 ms |
17568 KB |
Output is correct |
27 |
Correct |
79 ms |
21676 KB |
Output is correct |
28 |
Correct |
81 ms |
21300 KB |
Output is correct |
29 |
Correct |
92 ms |
29464 KB |
Output is correct |
30 |
Correct |
70 ms |
29188 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Correct |
106 ms |
17824 KB |
Output is correct |
33 |
Correct |
102 ms |
17908 KB |
Output is correct |
34 |
Correct |
93 ms |
21732 KB |
Output is correct |
35 |
Correct |
82 ms |
20152 KB |
Output is correct |
36 |
Correct |
103 ms |
17992 KB |
Output is correct |
37 |
Correct |
89 ms |
29432 KB |
Output is correct |
38 |
Correct |
89 ms |
29400 KB |
Output is correct |
39 |
Correct |
69 ms |
29144 KB |
Output is correct |
40 |
Correct |
82 ms |
21572 KB |
Output is correct |
41 |
Correct |
85 ms |
19248 KB |
Output is correct |
42 |
Correct |
2 ms |
4948 KB |
Output is correct |
43 |
Correct |
134 ms |
18060 KB |
Output is correct |
44 |
Correct |
117 ms |
17736 KB |
Output is correct |
45 |
Correct |
122 ms |
17636 KB |
Output is correct |
46 |
Correct |
106 ms |
16864 KB |
Output is correct |
47 |
Correct |
107 ms |
17108 KB |
Output is correct |
48 |
Correct |
83 ms |
21948 KB |
Output is correct |
49 |
Correct |
89 ms |
25572 KB |
Output is correct |
50 |
Correct |
77 ms |
13196 KB |
Output is correct |
51 |
Correct |
101 ms |
17028 KB |
Output is correct |
52 |
Correct |
85 ms |
19192 KB |
Output is correct |
53 |
Correct |
3 ms |
4948 KB |
Output is correct |
54 |
Correct |
2 ms |
4948 KB |
Output is correct |
55 |
Correct |
2 ms |
4980 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
3 ms |
5076 KB |
Output is correct |
58 |
Correct |
3 ms |
5076 KB |
Output is correct |
59 |
Correct |
3 ms |
5076 KB |
Output is correct |
60 |
Correct |
3 ms |
5076 KB |
Output is correct |
61 |
Correct |
3 ms |
5204 KB |
Output is correct |
62 |
Correct |
3 ms |
5076 KB |
Output is correct |
63 |
Correct |
3 ms |
5076 KB |
Output is correct |
64 |
Correct |
3 ms |
5076 KB |
Output is correct |
65 |
Correct |
3 ms |
5204 KB |
Output is correct |
66 |
Correct |
4 ms |
5076 KB |
Output is correct |
67 |
Correct |
88 ms |
21792 KB |
Output is correct |
68 |
Correct |
84 ms |
21228 KB |
Output is correct |
69 |
Correct |
98 ms |
17352 KB |
Output is correct |
70 |
Correct |
104 ms |
17712 KB |
Output is correct |
71 |
Correct |
103 ms |
17820 KB |
Output is correct |
72 |
Correct |
102 ms |
21688 KB |
Output is correct |
73 |
Correct |
85 ms |
16904 KB |
Output is correct |
74 |
Correct |
75 ms |
15592 KB |
Output is correct |
75 |
Correct |
77 ms |
22068 KB |
Output is correct |
76 |
Correct |
98 ms |
17572 KB |
Output is correct |
77 |
Correct |
81 ms |
21748 KB |
Output is correct |
78 |
Correct |
87 ms |
21248 KB |
Output is correct |
79 |
Correct |
89 ms |
29432 KB |
Output is correct |
80 |
Correct |
69 ms |
29180 KB |
Output is correct |
81 |
Correct |
102 ms |
17864 KB |
Output is correct |
82 |
Correct |
99 ms |
17980 KB |
Output is correct |
83 |
Correct |
86 ms |
21884 KB |
Output is correct |
84 |
Correct |
77 ms |
20240 KB |
Output is correct |
85 |
Correct |
99 ms |
17984 KB |
Output is correct |
86 |
Correct |
87 ms |
29404 KB |
Output is correct |
87 |
Correct |
87 ms |
29364 KB |
Output is correct |
88 |
Correct |
95 ms |
21632 KB |
Output is correct |
89 |
Correct |
84 ms |
19220 KB |
Output is correct |
90 |
Correct |
124 ms |
18028 KB |
Output is correct |
91 |
Correct |
125 ms |
17708 KB |
Output is correct |
92 |
Correct |
131 ms |
17688 KB |
Output is correct |
93 |
Correct |
118 ms |
17120 KB |
Output is correct |
94 |
Correct |
102 ms |
17112 KB |
Output is correct |
95 |
Correct |
81 ms |
21992 KB |
Output is correct |
96 |
Correct |
79 ms |
25576 KB |
Output is correct |
97 |
Correct |
89 ms |
13288 KB |
Output is correct |
98 |
Correct |
101 ms |
16864 KB |
Output is correct |
99 |
Correct |
85 ms |
19216 KB |
Output is correct |
100 |
Correct |
49 ms |
8264 KB |
Output is correct |
101 |
Correct |
132 ms |
17820 KB |
Output is correct |
102 |
Correct |
91 ms |
16016 KB |
Output is correct |
103 |
Correct |
115 ms |
18684 KB |
Output is correct |
104 |
Correct |
129 ms |
18632 KB |
Output is correct |