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
const int mod = 998244353;
struct dsu{
int n;
vector<vector<int>> available;
vector<int> sum, par, a;
dsu(int _n, vector<int> x){
n = _n;
sum = x;
par.resize(n);
a=x;
available.resize(n);
iota(par.begin(), par.end(), 0);
for(int i=0; i<n; i++){
available[i].push_back(i);
}
}
int find(int x){
if(par[x]==x) return x;
return par[x] = find(par[x]);
}
int merge(int x, int y){
int tx=x;
x = find(x); y=find(y);
if(x==y) return 0;
par[y] = x;
sum[x] += sum[y];
if(sum[y] <a[tx]) return 1;
if(available[y].size() > available[x].size()){
swap(available[x], available[y]);
}
while(available[y].size()){
available[x].push_back(available[y].back());
available[y].pop_back();
}
return 1;
}
};
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m; cin >> n >> m;
vector<int> a(n), id(n);
for(auto &i: a) cin >> i;
iota(id.begin(), id.end(), 0);
sort(id.begin(), id.end(), [&](int i, int j){
return a[i]<a[j];
});
vector<vector<int>> g(n);
dsu d(n, a);
for(int i=0; i<m; i++){
int x, y; cin >> x >> y;
x--; y--;
g[x].push_back(y);
g[y].push_back(x);
}
for(auto i: id){
for(auto v: g[i]){
if(a[v] <= a[i]){
d.merge(i, v);
}
}
}
vector<int> ar =d.available[d.find(id.back())];
vector<int> ans(n);
for(auto i: ar) ans[i]=1;
for(auto i: ans) cout<<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... |