#include <bits/stdc++.h>
#define int long long
using namespace std;
struct edge{
int u,v;
}e[200001];
int n,m,p[200001],a[200001];
set <int> s[200001];
string res;
int f(int i){
return (p[i]==i?i:p[i]=f(p[i]));
}
void unite(int u, int v){
int w=max(a[u],a[v]);
u=f(u);
v=f(v);
if (u==v)
return;
if (a[u]<w)
s[u].clear();
if (a[v]<w)
s[v].clear();
if (s[u].size()<s[v].size())
swap(u,v);
a[u]+=a[v];
p[v]=u;
for (int i:s[v])
s[u].insert(i);
s[v].clear();
}
int32_t main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n >> m;
for (int i=1;i<=n;i++){
cin >> a[i];
p[i]=i;
res+='0';
s[i].insert(i);
}
for (int i=0;i<m;i++)
cin >> e[i].u >> e[i].v;
sort(e,e+m,[](edge x, edge y){return max(a[x.u],a[x.v])<max(a[y.u],a[y.v]);});
for (int i=0;i<m;i++)
unite(e[i].u,e[i].v);
for (int i:s[f(1)])
res[i-1]='1';
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
6 ms |
9812 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Incorrect |
112 ms |
25704 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
243 ms |
25604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9628 KB |
Output is correct |
2 |
Incorrect |
217 ms |
25620 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
6 ms |
9812 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |