답안 #968686

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968686 2024-04-23T20:12:52 Z vladilius Stranded Far From Home (BOI22_island) C++17
0 / 100
210 ms 36780 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct dsu{
    vector<int> p, sz;
    vector<bool> out;
    vector<vector<int>> st;
    vector<ll> s;
    int n;
    dsu(int ns, vector<int>& x){
        n = ns;
        p.resize(n + 1);
        sz.resize(n + 1);
        s.resize(n + 1);
        out.assign(n + 1, 1);
        st.resize(n + 1);
        for (int i = 1; i <= n; i++){
            p[i] = i;
            sz[i] = 1;
            s[i] = x[i];
            st[i] = {i};
        }
    }
    int get(int v){
        if (p[v] != v){
            p[v] = get(p[v]);
        }
        return p[v];
    }
    void unite(int x, int y){
        x = get(x); y = get(y);
        if (x == y) return;
        if (sz[x] > sz[y]){
            swap(x, y);
        }
        p[x] = y;
        sz[y] += sz[x];
        for (int i: st[x]) st[y].push_back(i);
        s[y] += s[x];
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, m; cin>>n>>m;
    vector<int> x(n + 1), p = {0};
    for (int i = 1; i <= n; i++){
        cin>>x[i];
        p.push_back(i);
    }
    auto cmp = [&](int i, int j){
        return x[i] < x[j];
    };
    sort(p.begin(), p.end(), cmp);
    
    vector<int> g[n + 1];
    while (m--){
        int a, b; cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    int i = 1;
    dsu T(n, x);
    while (i <= n){
        int j = i;
        while (j <= n && x[p[i]] == x[p[j]]){
            j++;
        }
        for (int k = i; k < j; k++){
            int v = p[k];
            for (int u: g[v]){
                if (x[u] <= x[v]){
                    T.unite(u, v);
                }
            }
        }
        if (j > n) break;
        int nxt = x[p[j]];
        
        for (int k = i; k < j; k++){
            int v = p[k], g = T.get(v);
            ll s = T.s[g];
            if (s < nxt){
                for (int u: T.st[v]){
                    T.out[u] = 0;
                }
            }
        }
        
        i = j;
    }
    
    for (int i = 1; i <= n; i++){
        cout<<T.out[i];
    }
    cout<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 144 ms 29136 KB Output is correct
4 Correct 113 ms 34512 KB Output is correct
5 Incorrect 192 ms 36780 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 210 ms 35624 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 161 ms 30672 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 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 -