답안 #723109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723109 2023-04-13T08:47:20 Z dxz05 Stranded Far From Home (BOI22_island) C++17
10 / 100
1000 ms 16200 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 200500;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int n;
int s[N];
bool can[N];

struct dsu{
    vector<int> p;
    vector<long long> sum;

    dsu(){
        p.resize(n);
        iota(all(p), 0);

        sum.resize(n);
        for (int i = 0; i < n; i++) sum[i] = s[i];
    }

    int leader(int x){
        return (x == p[x] ? x : p[x] = leader(p[x]));
    }

    bool unite(int x, int y){
        int px = leader(x);
        int py = leader(y);
        if (px == py) return false;

        if (sum[px] < s[y]){
            for (int i = 0; i < n; i++){
                if (leader(i) == px) can[i] = false;
            }
        }
        if (sum[py] < s[x]){
            for (int i = 0; i < n; i++){
                if (leader(i) == py) can[i] = false;
            }
        }

        sum[py] += sum[px];
        p[px] = py;

        return true;
    }
};

vector<int> g[N];
void solve(){
    int m;
    cin >> n >> m;

    for (int i = 0; i < n; i++){
        cin >> s[i];
    }

    vector<pair<int, int>> edges;
    while (m--){
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
        if (s[u] > s[v]) swap(u, v);
        edges.emplace_back(u, v);
    }

    sort(all(edges), [](auto x, auto y){
        return s[x.second] < s[y.second];
    });

    fill(can, can + n, true);

    dsu d;
    for (auto [u, v] : edges){
        d.unite(u, v);
    }

    for (int i = 0; i < n; i++){
        cout << can[i];
    }

}

int main() {
    ios_base::sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 8 ms 5088 KB Output is correct
5 Correct 11 ms 5156 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 7 ms 5076 KB Output is correct
8 Correct 6 ms 5140 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 9 ms 5076 KB Output is correct
11 Correct 11 ms 5076 KB Output is correct
12 Correct 6 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 9 ms 5156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Execution timed out 1093 ms 16148 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Execution timed out 1065 ms 16092 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Execution timed out 1077 ms 16200 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 8 ms 5088 KB Output is correct
5 Correct 11 ms 5156 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 7 ms 5076 KB Output is correct
8 Correct 6 ms 5140 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 9 ms 5076 KB Output is correct
11 Correct 11 ms 5076 KB Output is correct
12 Correct 6 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 9 ms 5156 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Execution timed out 1093 ms 16148 KB Time limit exceeded
18 Halted 0 ms 0 KB -