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;
#define int long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct UFDS{
int p[200005];
UFDS(){
rep(x,0,200005) p[x]=x;
}
int par(int i){
if (p[i]==i) return i;
else return p[i]=par(p[i]);
}
} ufds;
int n,m;
int arr[200005];
vector<iii> edges;
set<int> s[200005];
signed main(){
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(false);
cin>>n>>m;
rep(x,1,n+1) cin>>arr[x];
int a,b;
rep(x,0,m){
cin>>a>>b;
if (arr[a]<arr[b]) swap(a,b);
edges.pub({arr[a],a,b});
}
sort(all(edges));
rep(x,1,n+1) s[x].insert(x);
for (auto [w,a,b]:edges){
a=ufds.par(a),b=ufds.par(b);
if (a==b) continue;
if (arr[b]>=w){
if (sz(s[a])<sz(s[b])) swap(s[a],s[b]);
for (auto it:s[b]) s[a].insert(it);
}
arr[a]+=arr[b];
ufds.p[b]=a;
}
int idx=ufds.par(1);
string ans(n,'0');
for (auto it:s[idx]) ans[it-1]='1';
cout<<ans<<endl;
}
# | 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... |