Submission #811115

# Submission time Handle Problem Language Result Execution time Memory
811115 2023-08-07T00:08:03 Z owoovo Stranded Far From Home (BOI22_island) C++14
0 / 100
4 ms 9740 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,tag[200010],subsum[200010],dsu[200010],ans[200010],vis[200010];
vector<ll> e[200010],te[200010];
pair<ll,ll> val[200010];
int f(int a){
    if(dsu[a]!=a){
        dsu[a]=f(dsu[a]);
        return dsu[a];
    }else{
        return a;
    }
}
void dfs(int now,int x){
    vis[now]=1;
    tag[now]==1?ans[now]=0:ans[now]=x;
    for(auto ne:te[now]){
        dfs(ne,ans[now]);
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>val[i].first;
        val[i].second=i;
        dsu[i]=i;
        subsum[i]=val[i].first;
    }
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;  
        if(a>b)swap(a,b);
        if(val[a].first>val[b].first)e[a].push_back(b);
        else e[b].push_back(a);
    }
    sort(&val[1],&val[n+1]);
    for(int i=1;i<=n;i++){
        ll x=val[i].second;
        ll y=val[i].first;
        cout<<x<<" "<<y<<"\n";
        for(auto ne:e[x]){
            ne=f(ne);
            if(ne==x)continue;
            te[x].push_back(ne);
            if(subsum[ne]<y)tag[ne]=1;
            dsu[ne]=x;
            subsum[x]+=subsum[ne];
        }
    }
    for(int i=n;i>0;i--){
        if(vis[val[i].second]==0)dfs(val[i].second,1);
    }
    for(int i=1;i<=n;i++)cout<<ans[i];
    cout<<"\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 9740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 9692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -