#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 200005;
int f[MX];
int e[MX];
int n, m;
int a[MX];
vector<int> ans[MX];
vector<int> G[MX];
int fp(int u){
return e[u] < 0? u : e[u] = fp(e[u]);
}
void unon(int u, int v){
u = fp(u);
v = fp(v);
if(u == v) return;
if(e[u] > e[v]) swap(u, v);
e[u] += e[v];
f[u] += f[v];
e[v] = u;
f[v] = 0;
if(ans[u].size() < ans[v].size()) swap(ans[u], ans[v]);
for(int x: ans[v]) ans[u].push_back(x);
ans[v].clear();
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i=1; i<=n; i++) cin >> a[i];
for(int i=1; i<=m; i++){
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
vector<int> b(n);
for(int i=1; i<=n; i++) b[i - 1] = i;
sort(b.begin(), b.end(), [&](const int &i, const int &j) -> bool { return a[i] < a[j]; });
for(int i=1; i<=n; i++) f[i] = a[i];
for(int i=1; i<=n; i++) e[i] = -1;
for(int i=1; i<=n; i++) ans[i].push_back(i);
bitset<MX> active = 0;
for(int u: b){
int cur = u;
active[u] = 1;
for(int v: G[u]) if(active[v] && cur != fp(v)){
v = fp(v);
if(f[v] < a[u]) ans[v].clear();
unon(cur, v);
cur = fp(cur);
}
}
int u = fp(1);
bitset<MX> homo = 0;
for(int x: ans[u]) homo[x] =1;
for(int i=1; i<=n; i++) cout << homo[i];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
13048 KB |
Output is correct |
2 |
Correct |
3 ms |
12880 KB |
Output is correct |
3 |
Correct |
3 ms |
12880 KB |
Output is correct |
4 |
Correct |
3 ms |
13136 KB |
Output is correct |
5 |
Correct |
4 ms |
13136 KB |
Output is correct |
6 |
Correct |
4 ms |
13136 KB |
Output is correct |
7 |
Correct |
4 ms |
13008 KB |
Output is correct |
8 |
Correct |
4 ms |
13136 KB |
Output is correct |
9 |
Correct |
4 ms |
13164 KB |
Output is correct |
10 |
Correct |
4 ms |
13136 KB |
Output is correct |
11 |
Correct |
4 ms |
13136 KB |
Output is correct |
12 |
Correct |
3 ms |
13136 KB |
Output is correct |
13 |
Correct |
4 ms |
13136 KB |
Output is correct |
14 |
Correct |
3 ms |
13136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12880 KB |
Output is correct |
2 |
Correct |
3 ms |
12880 KB |
Output is correct |
3 |
Correct |
122 ms |
33040 KB |
Output is correct |
4 |
Correct |
142 ms |
41080 KB |
Output is correct |
5 |
Correct |
125 ms |
38584 KB |
Output is correct |
6 |
Correct |
128 ms |
38844 KB |
Output is correct |
7 |
Correct |
137 ms |
39672 KB |
Output is correct |
8 |
Correct |
171 ms |
39148 KB |
Output is correct |
9 |
Correct |
124 ms |
43060 KB |
Output is correct |
10 |
Correct |
83 ms |
34468 KB |
Output is correct |
11 |
Correct |
125 ms |
38328 KB |
Output is correct |
12 |
Correct |
135 ms |
33220 KB |
Output is correct |
13 |
Correct |
110 ms |
40892 KB |
Output is correct |
14 |
Correct |
102 ms |
37196 KB |
Output is correct |
15 |
Correct |
114 ms |
33444 KB |
Output is correct |
16 |
Correct |
89 ms |
31676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12880 KB |
Output is correct |
2 |
Correct |
164 ms |
40220 KB |
Output is correct |
3 |
Correct |
187 ms |
40000 KB |
Output is correct |
4 |
Correct |
123 ms |
42736 KB |
Output is correct |
5 |
Correct |
104 ms |
41780 KB |
Output is correct |
6 |
Correct |
173 ms |
39760 KB |
Output is correct |
7 |
Correct |
141 ms |
36164 KB |
Output is correct |
8 |
Correct |
129 ms |
36260 KB |
Output is correct |
9 |
Correct |
81 ms |
35144 KB |
Output is correct |
10 |
Correct |
127 ms |
36288 KB |
Output is correct |
11 |
Correct |
159 ms |
38456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12880 KB |
Output is correct |
2 |
Correct |
169 ms |
37280 KB |
Output is correct |
3 |
Correct |
159 ms |
33612 KB |
Output is correct |
4 |
Correct |
172 ms |
38956 KB |
Output is correct |
5 |
Correct |
162 ms |
38700 KB |
Output is correct |
6 |
Correct |
184 ms |
38332 KB |
Output is correct |
7 |
Correct |
106 ms |
39096 KB |
Output is correct |
8 |
Correct |
96 ms |
39356 KB |
Output is correct |
9 |
Correct |
78 ms |
26952 KB |
Output is correct |
10 |
Correct |
140 ms |
43064 KB |
Output is correct |
11 |
Correct |
138 ms |
38456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
13048 KB |
Output is correct |
2 |
Correct |
3 ms |
12880 KB |
Output is correct |
3 |
Correct |
3 ms |
12880 KB |
Output is correct |
4 |
Correct |
3 ms |
13136 KB |
Output is correct |
5 |
Correct |
4 ms |
13136 KB |
Output is correct |
6 |
Correct |
4 ms |
13136 KB |
Output is correct |
7 |
Correct |
4 ms |
13008 KB |
Output is correct |
8 |
Correct |
4 ms |
13136 KB |
Output is correct |
9 |
Correct |
4 ms |
13164 KB |
Output is correct |
10 |
Correct |
4 ms |
13136 KB |
Output is correct |
11 |
Correct |
4 ms |
13136 KB |
Output is correct |
12 |
Correct |
3 ms |
13136 KB |
Output is correct |
13 |
Correct |
4 ms |
13136 KB |
Output is correct |
14 |
Correct |
3 ms |
13136 KB |
Output is correct |
15 |
Correct |
3 ms |
12880 KB |
Output is correct |
16 |
Correct |
3 ms |
12880 KB |
Output is correct |
17 |
Correct |
122 ms |
33040 KB |
Output is correct |
18 |
Correct |
142 ms |
41080 KB |
Output is correct |
19 |
Correct |
125 ms |
38584 KB |
Output is correct |
20 |
Correct |
128 ms |
38844 KB |
Output is correct |
21 |
Correct |
137 ms |
39672 KB |
Output is correct |
22 |
Correct |
171 ms |
39148 KB |
Output is correct |
23 |
Correct |
124 ms |
43060 KB |
Output is correct |
24 |
Correct |
83 ms |
34468 KB |
Output is correct |
25 |
Correct |
125 ms |
38328 KB |
Output is correct |
26 |
Correct |
135 ms |
33220 KB |
Output is correct |
27 |
Correct |
110 ms |
40892 KB |
Output is correct |
28 |
Correct |
102 ms |
37196 KB |
Output is correct |
29 |
Correct |
114 ms |
33444 KB |
Output is correct |
30 |
Correct |
89 ms |
31676 KB |
Output is correct |
31 |
Correct |
3 ms |
12880 KB |
Output is correct |
32 |
Correct |
164 ms |
40220 KB |
Output is correct |
33 |
Correct |
187 ms |
40000 KB |
Output is correct |
34 |
Correct |
123 ms |
42736 KB |
Output is correct |
35 |
Correct |
104 ms |
41780 KB |
Output is correct |
36 |
Correct |
173 ms |
39760 KB |
Output is correct |
37 |
Correct |
141 ms |
36164 KB |
Output is correct |
38 |
Correct |
129 ms |
36260 KB |
Output is correct |
39 |
Correct |
81 ms |
35144 KB |
Output is correct |
40 |
Correct |
127 ms |
36288 KB |
Output is correct |
41 |
Correct |
159 ms |
38456 KB |
Output is correct |
42 |
Correct |
3 ms |
12880 KB |
Output is correct |
43 |
Correct |
169 ms |
37280 KB |
Output is correct |
44 |
Correct |
159 ms |
33612 KB |
Output is correct |
45 |
Correct |
172 ms |
38956 KB |
Output is correct |
46 |
Correct |
162 ms |
38700 KB |
Output is correct |
47 |
Correct |
184 ms |
38332 KB |
Output is correct |
48 |
Correct |
106 ms |
39096 KB |
Output is correct |
49 |
Correct |
96 ms |
39356 KB |
Output is correct |
50 |
Correct |
78 ms |
26952 KB |
Output is correct |
51 |
Correct |
140 ms |
43064 KB |
Output is correct |
52 |
Correct |
138 ms |
38456 KB |
Output is correct |
53 |
Correct |
3 ms |
12880 KB |
Output is correct |
54 |
Correct |
3 ms |
12880 KB |
Output is correct |
55 |
Correct |
3 ms |
12880 KB |
Output is correct |
56 |
Correct |
4 ms |
13136 KB |
Output is correct |
57 |
Correct |
4 ms |
13136 KB |
Output is correct |
58 |
Correct |
4 ms |
13204 KB |
Output is correct |
59 |
Correct |
4 ms |
13304 KB |
Output is correct |
60 |
Correct |
4 ms |
13136 KB |
Output is correct |
61 |
Correct |
4 ms |
13136 KB |
Output is correct |
62 |
Correct |
4 ms |
13136 KB |
Output is correct |
63 |
Correct |
4 ms |
13136 KB |
Output is correct |
64 |
Correct |
3 ms |
13136 KB |
Output is correct |
65 |
Correct |
3 ms |
13136 KB |
Output is correct |
66 |
Correct |
4 ms |
13136 KB |
Output is correct |
67 |
Correct |
110 ms |
33040 KB |
Output is correct |
68 |
Correct |
107 ms |
39612 KB |
Output is correct |
69 |
Correct |
137 ms |
38584 KB |
Output is correct |
70 |
Correct |
136 ms |
39100 KB |
Output is correct |
71 |
Correct |
141 ms |
39160 KB |
Output is correct |
72 |
Correct |
137 ms |
39612 KB |
Output is correct |
73 |
Correct |
117 ms |
43192 KB |
Output is correct |
74 |
Correct |
92 ms |
34496 KB |
Output is correct |
75 |
Correct |
92 ms |
37876 KB |
Output is correct |
76 |
Correct |
140 ms |
36292 KB |
Output is correct |
77 |
Correct |
104 ms |
39868 KB |
Output is correct |
78 |
Correct |
114 ms |
40124 KB |
Output is correct |
79 |
Correct |
85 ms |
36284 KB |
Output is correct |
80 |
Correct |
69 ms |
35260 KB |
Output is correct |
81 |
Correct |
139 ms |
39604 KB |
Output is correct |
82 |
Correct |
147 ms |
40756 KB |
Output is correct |
83 |
Correct |
110 ms |
42168 KB |
Output is correct |
84 |
Correct |
111 ms |
41780 KB |
Output is correct |
85 |
Correct |
157 ms |
40476 KB |
Output is correct |
86 |
Correct |
113 ms |
36252 KB |
Output is correct |
87 |
Correct |
130 ms |
36168 KB |
Output is correct |
88 |
Correct |
123 ms |
35752 KB |
Output is correct |
89 |
Correct |
165 ms |
37528 KB |
Output is correct |
90 |
Correct |
169 ms |
37172 KB |
Output is correct |
91 |
Correct |
143 ms |
37956 KB |
Output is correct |
92 |
Correct |
144 ms |
37688 KB |
Output is correct |
93 |
Correct |
147 ms |
43140 KB |
Output is correct |
94 |
Correct |
122 ms |
39072 KB |
Output is correct |
95 |
Correct |
95 ms |
38468 KB |
Output is correct |
96 |
Correct |
85 ms |
37820 KB |
Output is correct |
97 |
Correct |
71 ms |
26220 KB |
Output is correct |
98 |
Correct |
134 ms |
43192 KB |
Output is correct |
99 |
Correct |
150 ms |
37688 KB |
Output is correct |
100 |
Correct |
35 ms |
18760 KB |
Output is correct |
101 |
Correct |
156 ms |
36544 KB |
Output is correct |
102 |
Correct |
118 ms |
34908 KB |
Output is correct |
103 |
Correct |
127 ms |
33216 KB |
Output is correct |
104 |
Correct |
171 ms |
36268 KB |
Output is correct |