Submission #927710

# Submission time Handle Problem Language Result Execution time Memory
927710 2024-02-15T09:13:32 Z berr Stranded Far From Home (BOI22_island) C++17
0 / 100
181 ms 46392 KB
//ᓚᘏᗢ
 
#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[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
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Incorrect 1 ms 604 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 110 ms 40248 KB Output is correct
4 Incorrect 130 ms 44268 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 164 ms 45200 KB Output is correct
3 Correct 181 ms 44676 KB Output is correct
4 Incorrect 114 ms 46392 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 176 ms 41788 KB Output is correct
3 Correct 157 ms 42812 KB Output is correct
4 Correct 160 ms 44660 KB Output is correct
5 Incorrect 174 ms 44892 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Incorrect 1 ms 604 KB Output isn't correct
7 Halted 0 ms 0 KB -