# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1029980 | hasan2006 | Stranded Far From Home (BOI22_island) | C++17 | 415 ms | 104636 KiB |
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 TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"
const int N = 5e5 + 9 , mod = 1e9 + 7;
ll a[N] , b[N] , dp[N] , c[N] , d[N] , p[N] , sz[N];
vector<int>v[N];
set<int>st[N];
ll get(int x){
return (p[x] == x ? x : get(p[x]));
}
void join(int x , int y , int k){
x = get(x);
y = get(y);
if(c[x] >= k){
if(st[x].size() > st[y].size())
swap(st[x] , st[y]);
for(auto to : st[x])
st[y].insert(to);
}
if(x != y){
if(sz[x] > sz[y])
swap( x, y) , swap(st[x] , st[y]);
p[x] = y;
sz[y] += sz[x];
c[y] += c[x];
}
}
void solve()
{
ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
cin>>n>>m;
vector<pair<int,int>>vc;
for(i = 1;i <= n; i++){
cin>>a[i];
p[i] = i , sz[i] = 1, c[i] = a[i] , st[i].insert(i);
vc.pb({a[i] , i});
}
for(i = 1; i <= m; i++){
cin>>l>>r;
v[l].pb(r);
v[r].pb(l);
}
sort(all(vc));
for(auto o : vc){
x = o.se , y =o.fi;
//cout<<x<<" ";
d[x] = 1;
for(auto to : v[x])
if(get(to) != get(x) && d[to] == 1)
join(to , x , y);
}
for(i = 1; i <= n; i++)
cout<<(st[get(i)].find(i) != st[get(i)].end());
}
int main(){
TL;
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
int t = 1;
//cin>>t;
while(t--)
{
solve();
}
}
// Author : حسن
Compilation message (stderr)
# | 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... |