답안 #572679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572679 2022-06-05T03:18:55 Z jlallas384 Stranded Far From Home (BOI22_island) C++17
0 / 100
219 ms 45564 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct ufds{
    vector<int> par;
    ufds(int n): par(n){
        iota(par.begin(), par.end(), 0);
    }
    int find(int a){
        return a == par[a] ? a : par[a] = find(par[a]);
    }
    int unite(int a,int b){
        a = find(a), b = find(b);
        if(a == b) return 0;
        par[b] = a;
        return 1;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<int> s(n);
    for(int &x: s){
        cin >> x;
    }
    vector<vector<int>> g(n);
    while(m--){
        int u,v;
        cin >> u >> v,u--,v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> ok(n);
    vector<pair<int,int>> srt;
    for(int i = 0; i < n; i++){
        srt.emplace_back(s[i],i);
    }
    sort(srt.begin(), srt.end());
    vector<vector<int>> tree(n);
    ufds ds(n);
    for(auto [x,v]: srt){
        for(int u: g[v]) if(ok[u]){
            if(ok[u] && ds.find(u) != ds.find(v)){
                tree[v].push_back(ds.find(u));
                ds.unite(v,u);
            }
        }
        ok[v] = 1;
    }
    vector<ll> sums;
    for(auto x: s){
        sums.push_back(x);
    }
    vector<int> ans(n);
    function <void(int)> dfs = [&](int v){
        ans[v] = 1;
        for(int u: tree[v]){
            dfs(u);
            ans[u] &= s[v] <= sums[u];
            sums[v] += sums[u];
        }
    };
    dfs(ds.find(0));
    for(int x: ans){
        cout << x;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 596 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 154 ms 34248 KB Output is correct
4 Incorrect 143 ms 45564 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 219 ms 27004 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 207 ms 27416 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 596 KB Output isn't correct
5 Halted 0 ms 0 KB -