답안 #968695

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

struct dsu{
    vector<int> p, sz;
    vector<bool> out;
    vector<vector<int>> all;
    vector<ll> s;
    set<pii> st;
    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);
        all.resize(n + 1);
        for (int i = 1; i <= n; i++){
            p[i] = i;
            sz[i] = 1;
            s[i] = x[i];
            all[i] = {i};
            st.insert({s[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);
        }
        auto it = st.find({s[y], y});
        if (it != st.end()) st.erase(it);
        it = st.find({s[x], x});
        if (it != st.end()) st.erase(it);
        p[x] = y;
        sz[y] += sz[x];
        for (int i: all[x]) all[y].push_back(i);
        s[y] += s[x];
        st.insert({s[y], y});
    }
};

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]];
       
        while (!T.st.empty()){
            auto [s, v] = *(T.st.begin());
            if (s >= nxt) break;
            for (int i: T.all[v]){
                T.out[i] = 0;
            }
            T.st.erase(T.st.begin());
        }
        
        i = j;
    }
    
    for (int i = 1; i <= n; i++){
        cout<<T.out[i];
    }
    cout<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 2 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 1093 ms 37256 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 460 ms 43552 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 356 ms 39612 KB Output isn't correct
3 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 1 ms 348 KB Output is correct
4 Incorrect 2 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -