#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
int n,m;
cin>>n>>m;
vector<ll> s(n);
vector<int> t(n,-1);
vector<int> ord(n);
vector<vector<int>> bosses(n);
vector<vector<int>> g(n);
for (int i=0;i<n;i++) {
cin>>s[i];
ord[i]=i;
bosses[i]={i};
}
sort(ord.begin(),ord.end(),[&](int i,int j){return s[i]<s[j];});
for (int i=0;i<m;i++) {
int a,b;
cin>>a>>b;
a--, b--;
g[a].push_back(b);
g[b].push_back(a);
}
function<int(int)>root=[&](int a){
if(t[a]==a){
return a;
}else{
return t[a]=root(t[a]);
}
};
function<void(int,int)>join=[&](int a,int b){
a=root(a);
b=root(b);
if(a==b){
assert(0);
return;
}
if ((int)bosses[a].size()>(int)bosses[b].size()){
swap(a,b);
}
t[a]=b;
s[b]+=s[a];
for (auto &boss:bosses[a]){
bosses[b].push_back(boss);
}
};
for (auto &v:ord){
/// activate vertex v
vector<int> comps;
for (auto &ngh:g[v]){
if (t[ngh]!=-1){
comps.push_back(root(ngh));
}
}
sort(comps.begin(),comps.end());
comps.resize(unique(comps.begin(),comps.end())-comps.begin());
t[v]=v;
for (auto &c:comps){
if (s[c]<s[v]){
bosses[c].clear();
}
}
for(auto&c:comps){
join(v,c);
}
}
vector<int> isboss(n,0);
for (auto &boss:bosses[root(0)]){
isboss[boss]=1;
}
for (auto &is:isboss){
cout<<is;
}
cout<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
636 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
636 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
171 ms |
31548 KB |
Output is correct |
4 |
Correct |
178 ms |
33364 KB |
Output is correct |
5 |
Correct |
190 ms |
32468 KB |
Output is correct |
6 |
Correct |
198 ms |
33552 KB |
Output is correct |
7 |
Correct |
226 ms |
33560 KB |
Output is correct |
8 |
Correct |
194 ms |
32804 KB |
Output is correct |
9 |
Correct |
188 ms |
35432 KB |
Output is correct |
10 |
Correct |
128 ms |
31160 KB |
Output is correct |
11 |
Correct |
129 ms |
31872 KB |
Output is correct |
12 |
Correct |
220 ms |
31000 KB |
Output is correct |
13 |
Correct |
169 ms |
33672 KB |
Output is correct |
14 |
Correct |
180 ms |
33388 KB |
Output is correct |
15 |
Correct |
151 ms |
31644 KB |
Output is correct |
16 |
Correct |
103 ms |
30640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
322 ms |
34244 KB |
Output is correct |
3 |
Correct |
298 ms |
34496 KB |
Output is correct |
4 |
Correct |
202 ms |
35292 KB |
Output is correct |
5 |
Correct |
191 ms |
33516 KB |
Output is correct |
6 |
Correct |
304 ms |
34472 KB |
Output is correct |
7 |
Correct |
233 ms |
31636 KB |
Output is correct |
8 |
Correct |
210 ms |
31704 KB |
Output is correct |
9 |
Correct |
114 ms |
30732 KB |
Output is correct |
10 |
Correct |
217 ms |
32068 KB |
Output is correct |
11 |
Correct |
226 ms |
32636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
241 ms |
32124 KB |
Output is correct |
3 |
Correct |
221 ms |
32692 KB |
Output is correct |
4 |
Correct |
277 ms |
33604 KB |
Output is correct |
5 |
Correct |
225 ms |
34380 KB |
Output is correct |
6 |
Correct |
206 ms |
31628 KB |
Output is correct |
7 |
Correct |
142 ms |
32700 KB |
Output is correct |
8 |
Correct |
119 ms |
32232 KB |
Output is correct |
9 |
Correct |
133 ms |
17620 KB |
Output is correct |
10 |
Correct |
221 ms |
33848 KB |
Output is correct |
11 |
Correct |
190 ms |
32864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
636 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
636 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
171 ms |
31548 KB |
Output is correct |
18 |
Correct |
178 ms |
33364 KB |
Output is correct |
19 |
Correct |
190 ms |
32468 KB |
Output is correct |
20 |
Correct |
198 ms |
33552 KB |
Output is correct |
21 |
Correct |
226 ms |
33560 KB |
Output is correct |
22 |
Correct |
194 ms |
32804 KB |
Output is correct |
23 |
Correct |
188 ms |
35432 KB |
Output is correct |
24 |
Correct |
128 ms |
31160 KB |
Output is correct |
25 |
Correct |
129 ms |
31872 KB |
Output is correct |
26 |
Correct |
220 ms |
31000 KB |
Output is correct |
27 |
Correct |
169 ms |
33672 KB |
Output is correct |
28 |
Correct |
180 ms |
33388 KB |
Output is correct |
29 |
Correct |
151 ms |
31644 KB |
Output is correct |
30 |
Correct |
103 ms |
30640 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
322 ms |
34244 KB |
Output is correct |
33 |
Correct |
298 ms |
34496 KB |
Output is correct |
34 |
Correct |
202 ms |
35292 KB |
Output is correct |
35 |
Correct |
191 ms |
33516 KB |
Output is correct |
36 |
Correct |
304 ms |
34472 KB |
Output is correct |
37 |
Correct |
233 ms |
31636 KB |
Output is correct |
38 |
Correct |
210 ms |
31704 KB |
Output is correct |
39 |
Correct |
114 ms |
30732 KB |
Output is correct |
40 |
Correct |
217 ms |
32068 KB |
Output is correct |
41 |
Correct |
226 ms |
32636 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
241 ms |
32124 KB |
Output is correct |
44 |
Correct |
221 ms |
32692 KB |
Output is correct |
45 |
Correct |
277 ms |
33604 KB |
Output is correct |
46 |
Correct |
225 ms |
34380 KB |
Output is correct |
47 |
Correct |
206 ms |
31628 KB |
Output is correct |
48 |
Correct |
142 ms |
32700 KB |
Output is correct |
49 |
Correct |
119 ms |
32232 KB |
Output is correct |
50 |
Correct |
133 ms |
17620 KB |
Output is correct |
51 |
Correct |
221 ms |
33848 KB |
Output is correct |
52 |
Correct |
190 ms |
32864 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
2 ms |
592 KB |
Output is correct |
57 |
Correct |
2 ms |
596 KB |
Output is correct |
58 |
Correct |
2 ms |
460 KB |
Output is correct |
59 |
Correct |
2 ms |
468 KB |
Output is correct |
60 |
Correct |
2 ms |
468 KB |
Output is correct |
61 |
Correct |
2 ms |
596 KB |
Output is correct |
62 |
Correct |
2 ms |
596 KB |
Output is correct |
63 |
Correct |
2 ms |
596 KB |
Output is correct |
64 |
Correct |
2 ms |
596 KB |
Output is correct |
65 |
Correct |
2 ms |
596 KB |
Output is correct |
66 |
Correct |
2 ms |
596 KB |
Output is correct |
67 |
Correct |
179 ms |
31708 KB |
Output is correct |
68 |
Correct |
173 ms |
33440 KB |
Output is correct |
69 |
Correct |
184 ms |
32580 KB |
Output is correct |
70 |
Correct |
198 ms |
33500 KB |
Output is correct |
71 |
Correct |
207 ms |
33636 KB |
Output is correct |
72 |
Correct |
201 ms |
32848 KB |
Output is correct |
73 |
Correct |
185 ms |
35572 KB |
Output is correct |
74 |
Correct |
131 ms |
31144 KB |
Output is correct |
75 |
Correct |
126 ms |
31892 KB |
Output is correct |
76 |
Correct |
184 ms |
31040 KB |
Output is correct |
77 |
Correct |
170 ms |
33756 KB |
Output is correct |
78 |
Correct |
172 ms |
33412 KB |
Output is correct |
79 |
Correct |
146 ms |
31632 KB |
Output is correct |
80 |
Correct |
106 ms |
30700 KB |
Output is correct |
81 |
Correct |
236 ms |
34204 KB |
Output is correct |
82 |
Correct |
230 ms |
34316 KB |
Output is correct |
83 |
Correct |
186 ms |
35360 KB |
Output is correct |
84 |
Correct |
158 ms |
33436 KB |
Output is correct |
85 |
Correct |
242 ms |
34504 KB |
Output is correct |
86 |
Correct |
180 ms |
31612 KB |
Output is correct |
87 |
Correct |
187 ms |
31712 KB |
Output is correct |
88 |
Correct |
188 ms |
32072 KB |
Output is correct |
89 |
Correct |
211 ms |
32588 KB |
Output is correct |
90 |
Correct |
236 ms |
32104 KB |
Output is correct |
91 |
Correct |
235 ms |
32720 KB |
Output is correct |
92 |
Correct |
232 ms |
33608 KB |
Output is correct |
93 |
Correct |
235 ms |
34496 KB |
Output is correct |
94 |
Correct |
216 ms |
31552 KB |
Output is correct |
95 |
Correct |
150 ms |
32660 KB |
Output is correct |
96 |
Correct |
122 ms |
32292 KB |
Output is correct |
97 |
Correct |
119 ms |
17564 KB |
Output is correct |
98 |
Correct |
218 ms |
33852 KB |
Output is correct |
99 |
Correct |
189 ms |
32780 KB |
Output is correct |
100 |
Correct |
45 ms |
4892 KB |
Output is correct |
101 |
Correct |
247 ms |
32924 KB |
Output is correct |
102 |
Correct |
168 ms |
25916 KB |
Output is correct |
103 |
Correct |
204 ms |
26824 KB |
Output is correct |
104 |
Correct |
244 ms |
31452 KB |
Output is correct |