Submission #823741

# Submission time Handle Problem Language Result Execution time Memory
823741 2023-08-13T04:17:52 Z PoonYaPat Stranded Far From Home (BOI22_island) C++14
0 / 100
174 ms 29944 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int n,m,p[200005],r[200005];
ll c[200005],cnt[200005];
vector<int> ans[200005],adj[200005];
vector<pii> v;

int find(int x) {
    while (x!=p[x]) x=p[x];
    return x;
}

void unite(int x, int y) {
    x=find(x); y=find(y);
    if (x!=y) {
        if (r[x]<r[y]) swap(x,y);
        p[y]=x;
        cnt[x]+=cnt[y];
        if (r[x]==r[y]) ++r[x];
    }
}

void add(int x) {
    for (auto s : adj[x]) {
        if (c[x]<c[s]) continue;
        if (find(s)!=find(x)) {
            if (cnt[find(s)]>=c[x]) {
                if (ans[x].size()<ans[s].size()) swap(ans[x],ans[s]);
                for (auto k : ans[s]) ans[x].push_back(k);
            }
            unite(s,x);
        }
    }
}

bool Ans[200005];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for (int i=1; i<=n; ++i) cin>>c[i], p[i]=i, cnt[i]=c[i], v.push_back(pii(c[i],i)), ans[i].push_back(i);
    for (int i=0; i<m; ++i) {
        int a,b; cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    sort(v.begin(),v.end());
    for (auto s : v) add(s.second);
    for (auto s : ans[v.back().second]) Ans[s]=true;
    for (int i=1; i<=n; ++i) {
        if (Ans[i]) cout<<1;
        else cout<<0;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 4 ms 9700 KB Output is correct
4 Incorrect 5 ms 9796 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Incorrect 113 ms 29944 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Incorrect 174 ms 28796 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9940 KB Output is correct
2 Incorrect 165 ms 28848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 4 ms 9700 KB Output is correct
4 Incorrect 5 ms 9796 KB Output isn't correct
5 Halted 0 ms 0 KB -