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;
typedef long long ll;
#define x first
#define y second
struct DSUF{
vector<ll> P,S;
vector<vector<ll>> E;
ll Find(ll i){
if(i==P[i]) return i;
return P[i]=Find(P[i]);
}
void Union(ll a, ll b){
a=Find(a);
b=Find(b);
if(a==b) return;
if(S[a]<S[b])swap(a,b);
S[a]+=S[b]; P[b]=a;
for(auto i:E[b]) E[a].push_back(i);
}
bool Same(ll a, ll b) { return (Find(a)==Find(b)); }
ll Size(ll a) { return S[a]; }
DSUF(ll n,vector<ll> cad)
{
P.assign(n+5,0);
S.assign(n+5,0);
E.resize(n+5);
for(int i=1; i<=n; i++)
S[i]=cad[i];
for(int i=0; i<P.size(); i++){
P[i]=i;
E[i].push_back(i);
}
}
};
int main()
{
ll n,m;
cin>>n>>m;
vector<ll> cad(n+1);
vector<ll>sol(n+1,0);
for(int i=1; i<=n; i++)
cin>>cad[i];
priority_queue<pair<ll,pair<ll,ll>>> q;
for(int i=0; i<m; i++)
{
ll a,b;
cin>>a>>b;
if(cad[a]<cad[b]) swap(a,b);
q.push({-cad[a],{a,b}});
}
DSUF asd(n,cad);
while (!q.empty())
{
ll a=q.top().x;
vector<pair<ll,ll>> temp;
while(!q.empty()&&q.top().x==a){
temp.push_back(q.top().y);
q.pop();
}
for(int i=0; i<temp.size(); i++)
{
temp[i].x=asd.Find(temp[i].x);
temp[i].y=asd.Find(temp[i].y);
}
sort(temp.begin(),temp.end());
vector<pair<ll,ll>> temp2;temp2.push_back(temp[0]);
for(int i=1; i<temp.size(); i++)
if(temp[i]!=temp[i-1])
temp2.push_back(temp[i]);
for(auto i:temp2)
if(asd.Size(i.y)<cad[i.x])
asd.E[i.y].clear();
for(auto i:temp2)
asd.Union(i.x,i.y);
}
for(auto i:asd.E[asd.Find(1)])
sol[i]=1;
for(int i=1; i<=n; i++)
cout<<sol[i];
return 0;
}
Compilation message (stderr)
island.cpp: In constructor 'DSUF::DSUF(ll, std::vector<long long int>)':
island.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=0; i<P.size(); i++){
| ~^~~~~~~~~
island.cpp: In function 'int main()':
island.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i=0; i<temp.size(); i++)
| ~^~~~~~~~~~~~
island.cpp:68:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i=1; i<temp.size(); i++)
| ~^~~~~~~~~~~~
# | 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... |