답안 #869476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869476 2023-11-04T12:16:59 Z lolismek Stranded Far From Home (BOI22_island) C++14
0 / 100
237 ms 23208 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];

pii e[NMAX + 1];

int main(){

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

    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]);
    }

    vector <pii> aux;
    for(int i = 1; i <= m; i++){
        int a, b;
        fin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        e[i] = {a, b};
        aux.push_back({max(v[a], v[b]), i});
    }

    sort(aux.begin(), aux.end());

    for(pii x : aux){
        Join(e[x.second].first, e[x.second].second);
    }

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

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 13144 KB Output is correct
2 Correct 3 ms 13148 KB Output is correct
3 Correct 2 ms 13148 KB Output is correct
4 Incorrect 4 ms 13240 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13148 KB Output is correct
2 Correct 3 ms 13180 KB Output is correct
3 Incorrect 199 ms 22712 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13184 KB Output is correct
2 Incorrect 237 ms 23208 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13148 KB Output is correct
2 Incorrect 201 ms 22736 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 13144 KB Output is correct
2 Correct 3 ms 13148 KB Output is correct
3 Correct 2 ms 13148 KB Output is correct
4 Incorrect 4 ms 13240 KB Output isn't correct
5 Halted 0 ms 0 KB -