Submission #869473

# Submission time Handle Problem Language Result Execution time Memory
869473 2023-11-04T12:11:35 Z lolismek Stranded Far From Home (BOI22_island) C++14
0 / 100
368 ms 35468 KB
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>

#define pii pair <int, int>


using namespace std;

//ifstream fin("input.in");
//ofstream fout("output.out");

#define fin cin
#define fout cout

const int NMAX = 2e5;

int v[NMAX + 1];
vector <int> adj[NMAX + 1];

int par[NMAX + 1];
int sum[NMAX + 1];

bool bad[NMAX + 1];
int Find(int x){
    if(x == par[x]){
        return x;
    }
    int y = Find(par[x]); // ?
    bad[x] |= bad[par[x]];
    par[x] = y;
    return par[x];
}

void Join(int x, int y){
    x = par[x];
    y = par[y];

    if(v[x] < v[y]){
        swap(x, y);
    }

    if(v[x] > sum[y]){
        bad[y] = 1;
    }

    par[y] = x;
    sum[x] += sum[y];
}

bool ins[NMAX + 1];

void Insert(int x){
    ins[x] = true;
    for(int vec : adj[x]){
        if(ins[vec]){
            Join(vec, x);
        }
    }
}

vector <int> inds[NMAX + 1];

int main(){

    int n, m;
    cin >> n >> m;

    priority_queue <pii, vector <pii>, greater <pii>> pq;

    vector <int> vals;
    for(int i = 1; i <= n; i++){
        cin >> v[i];
        par[i] = i;
        sum[i] = v[i];
        vals.push_back(v[i]);
    }

    for(int i = 1; i <= m; i++){
        int a, b;
        fin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    sort(vals.begin(), vals.end());
    vals.erase(unique(vals.begin(), vals.end()), vals.end());

    map <int, int> norm;
    for(int i = 0; i < (int)vals.size(); i++){
        norm[vals[i]] = i;
    }

    for(int i = 1; i <= n; i++){
        inds[norm[v[i]]].push_back(i);
    }

    for(int val = 0; val < (int)vals.size(); val++){
        for(int ind : inds[val]){
            Insert(ind);
        }
    }

    for(int i = 1; i <= n; i++){
        Find(i);
        cout << !bad[i];
    }
    cout << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11612 KB Output is correct
2 Correct 2 ms 11612 KB Output is correct
3 Correct 2 ms 11612 KB Output is correct
4 Incorrect 4 ms 11868 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11612 KB Output is correct
2 Correct 3 ms 11612 KB Output is correct
3 Incorrect 258 ms 35468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11608 KB Output is correct
2 Incorrect 368 ms 35268 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11612 KB Output is correct
2 Incorrect 226 ms 21024 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11612 KB Output is correct
2 Correct 2 ms 11612 KB Output is correct
3 Correct 2 ms 11612 KB Output is correct
4 Incorrect 4 ms 11868 KB Output isn't correct
5 Halted 0 ms 0 KB -