Submission #951779

# Submission time Handle Problem Language Result Execution time Memory
951779 2024-03-22T15:26:51 Z Ludissey Stranded Far From Home (BOI22_island) C++14
0 / 100
158 ms 25592 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define sz(a) (int)a.size()
const int mod=1e9+7;
vector<int> parent;
vector<vector<int>> neigh;
vector<bool> poss;
vector<int> sz;
vector<int> sum;
vector<int> v;

int getParent(int a){
    if(parent[a]==a) return a;
    return parent[a]=getParent(parent[a]);
}

void unite(int a, int b){
    a=getParent(a); b=getParent(b);
    if(a==b) return;
    if(sum[a]<sum[b]) swap(a,b);
    sz[a]+=sz[b];
    sum[a]+=sum[b];
    parent[b]=a;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    sz.resize(N,1); poss.resize(N,true); parent.resize(N); neigh.resize(N); v.resize(N); sum.resize(N);
    priority_queue<pair<int,int>> pq;
    for (int i = 0; i < N; i++) { 
        cin >> v[i]; parent[i]=i; sum[i]=v[i]; pq.push({-v[i], i}); 
    }
    for (int i = 0; i < M; i++) { 
        int u,vs;  cin >> u >> vs;
        neigh[u-1].push_back(vs-1); 
        neigh[vs-1].push_back(u-1);
    }
    while(!pq.empty()){
        int i=pq.top().second; pq.pop();
        for (auto u:neigh[i])
        {
            if(v[u]<=v[i]) {
                if(sum[getParent(u)]<v[i]) {
                    poss[getParent(u)]=false;
                    sum[i]+=sum[u];
                }
                else unite(u,i);
            }
        }
        

    }
    for (int i = 0; i < N; i++){
        cout << poss[getParent(i)] << "";
    }
    cout << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 604 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 0 ms 348 KB Output is correct
3 Correct 109 ms 21816 KB Output is correct
4 Correct 112 ms 22468 KB Output is correct
5 Incorrect 126 ms 25592 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 143 ms 20744 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 158 ms 21956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -