This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n,m;
int b[200001];
pair<int,int> a[200001];
vector<int> v[200001];
void read()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i].first;
b[i]=a[i].first;
a[i].second=i;
}
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
}
pair<int,int> p[200001];
long long sz[200001];
pair<int,int> parent(int x)
{
if(x==p[x].first)return p[x];
pair<int,int> y=parent(p[x].first);
y.second=max(y.second,p[x].second);
return p[x]=y;
}
void unite(int i,int j)
{
pair<int,int> pi=parent(i);
pair<int,int> pj=parent(j);
if(pi.first==pj.first)return;
//cout<<i<<" "<<j<<" "<<pi.first<<" "<<pj.first<<endl;
i=pi.first;
j=pj.first;
sz[i]+=sz[j];
p[j].first=i;
}
void solve()
{
for(int i=1;i<=n;i++)
{
p[i].first=i;
sz[i]=a[i].first;
}
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)
{
int vr=a[i].second;
//cout<<a[i].first<<" "<<vr<<"!"<<endl;
for(int j=0;j<v[vr].size();j++)
{
int nb=v[vr][j];
pair<int,int> pnb=parent(nb);
nb=pnb.first;
if(sz[nb]<sz[vr])
p[nb].second=1;
}
for(int j=0;j<v[vr].size();j++)
{
int nb=v[vr][j];
if(b[nb]<=b[vr])
unite(vr,nb);
}
}
for(int i=1;i<=n;i++)
{
pair<int,int> p=parent(i);
cout<<(1^p.second);
}
cout<<endl;
}
int main()
{
read();
solve();
return 0;
}
/*
7 6
2 2 1 1 8 5 5
1 2
2 3
3 4
4 5
5 6
6 7
*/
Compilation message (stderr)
island.cpp: In function 'void solve()':
island.cpp:65:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int j=0;j<v[vr].size();j++)
| ~^~~~~~~~~~~~~
island.cpp:74:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int j=0;j<v[vr].size();j++)
| ~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |