답안 #1098927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098927 2024-10-10T10:22:34 Z crafticat Stranded Far From Home (BOI22_island) C++17
10 / 100
1000 ms 29620 KB
#include <bits/stdc++.h>

#include <utility>

using ll = long long;
using namespace std;
#define F0R(i, n) for (ll i= 0; i < n;i++)
template<typename T>
using V = vector<T>;
using vi = V<ll>;
using vvi = V<vi>;
#define pb push_back
using pi = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define f first
#define s second

V<ll> initSum;

struct dsu {
    vi par;
    vi siz;
    vi sum;

    dsu(ll n, vi initSum) {
        par.resize(n, -1);
        siz.resize(n, 1);
        sum = std::move(initSum);
    }

    ll get(ll x) {
        if (par[x] == -1) return x;
        return get(par[x]);
    }

    void combine(ll a, ll b) {
        a = get(a), b = get(b);
        if (a == b) return;

        if (initSum[b] > initSum[a]) swap(a,b);
        siz[a] += siz[b];
        sum[a] += sum[b];
        par[b] = a;
    }
};

//TODO CHECK CONNECTIVITY
vvi genGraph(vi par) {
    vvi g(par.size());

    F0R(i, par.size()) {
        if (par[i] == -1) continue;
        g[par[i]].pb(i);
        g[i].pb(par[i]);
    }
    return g;
}
V<bool> possible;
dsu* dsu;
vvi g;

void dfsPos(ll x, ll p) {
    if (p == -1 || dsu->sum[x] >= initSum[p]) possible[x] = true;
    else return;

    for (auto child : g[x]) {
        if (child == p) continue;
        dfsPos(child, x);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    ll n, m; cin >> n >> m;
    V<pair<ll, pi>> edges;
    initSum.resize(n + 1);

    F0R(i, n)
        cin >> initSum[i + 1];

    F0R(i, m) {
        ll a, b; cin >> a>> b;
        edges.pb({max(initSum[a], initSum[b]), {a, b}});
    }

    sort(all(edges));
    dsu = new struct dsu(n + 1, initSum);

    for (auto [x,pa] : edges) {
        auto [a,b] = pa;
        dsu->combine(a,b);
    }

    g = genGraph(dsu->par);
    ll root = dsu->get(1);
    bool pos = true;
    F0R(i, n)
        if (dsu->get(i + 1) != root) pos = false;

    possible.resize(n + 1);

    if (pos) dfsPos(root, -1);
    F0R(i, n) {
        cout << possible[i + 1] << "";
    }

    return 0;
}

Compilation message

island.cpp: In function 'vvi genGraph(vi)':
island.cpp:7:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int, std::allocator<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define F0R(i, n) for (ll i= 0; i < n;i++)
......
   51 |     F0R(i, par.size()) {
      |         ~~~~~~~~~~~~~              
island.cpp:51:5: note: in expansion of macro 'F0R'
   51 |     F0R(i, par.size()) {
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 1092 ms 24760 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 99 ms 24924 KB Output is correct
3 Correct 100 ms 29368 KB Output is correct
4 Execution timed out 1035 ms 29620 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 1088 ms 24960 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Execution timed out 1092 ms 24760 KB Time limit exceeded
18 Halted 0 ms 0 KB -