답안 #716043

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
716043 2023-03-28T20:27:29 Z MojoLake Stranded Far From Home (BOI22_island) C++17
0 / 100
324 ms 25380 KB
#include <bits/stdc++.h>

#define debug(x) cout << #x << ": " << x << "\n"
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

const int N = 2e5 + 5;
const int inf = 1e9;
const ll LLinf = 1e16;

int siz[N], rep[N];
ll sum[N];
bool lose[N];
vector<int> child[N];

int id(int x){
    while(rep[x]!=x)x=rep[x];
    return x;
}

bool same(int a, int b){
    return id(a) == id(b);
}

void connect(int a, int b){
    a = id(a); b = id(b);
    if(siz[a] > siz[b])swap(a, b);
    siz[b] += siz[a];
    sum[b] += sum[a];
    rep[a] = b;
    child[b].push_back(a);
}

void init_uf(){
    for(int i = 1; i < N; ++i){
        siz[i] = 1;
        rep[i] = i;
    }
}

ll pop[N];
vector<int> g[N];
bool res[N], hand[N];

void update_res(int cur, bool f){
    f = f || lose[cur];
    res[cur] = f;
    hand[cur] = 1;

    for(int nex : child[cur]){
        if(!hand[cur])update_res(nex, f);
    }
}

int main(){

    // if cannot get to any new ones:
    //      fail for this and its children
    // 
    // uf: size, sum, rep
    // kusee jos kaikki naapurit suurempii
    init_uf();
    int n, m;
    cin >> n >> m;
    vector<pair<ll, int>> v;
    for(int i = 1; i <= n; ++i){
        ll x; cin >> x;
        pop[i] = sum[i] = x;
        v.push_back({x, i});
    }
    sort(all(v));

    while(m--){
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for(auto [x, node] : v){
        vector<int> con;
        for(auto nex : g[node]){
            if(same(node, nex))continue;
            nex = id(nex);
            if(pop[node] > sum[nex]){
                lose[nex] = 1;
            }else if(pop[node] >= pop[nex]){
                con.push_back(nex);
            }
        }
        for(int nex : con)if(!same(node, nex))connect(node, nex);
    }

    for(int i = 1; i <= n; ++i){
        // cout << i << " " << id(i) << "\n";
        // cout << lose[i] << "\n";
        if(hand[id(i)])continue;
        // cout << "yea\n";
        update_res(id(i), 0);
    }
    for(int i = 1; i <= n; ++i){
        cout << !res[i];
    }
    cout << "\n";

    // 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11220 KB Output is correct
2 Correct 6 ms 11220 KB Output is correct
3 Correct 6 ms 11220 KB Output is correct
4 Incorrect 8 ms 11348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11220 KB Output is correct
2 Correct 6 ms 11220 KB Output is correct
3 Incorrect 308 ms 25380 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11220 KB Output is correct
2 Incorrect 294 ms 24472 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11220 KB Output is correct
2 Incorrect 324 ms 25012 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11220 KB Output is correct
2 Correct 6 ms 11220 KB Output is correct
3 Correct 6 ms 11220 KB Output is correct
4 Incorrect 8 ms 11348 KB Output isn't correct
5 Halted 0 ms 0 KB -