답안 #598566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598566 2022-07-18T14:04:34 Z someone Stranded Far From Home (BOI22_island) C++14
0 / 100
178 ms 42120 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct Node {
    int id, nbHab;
};

const int N = 2e5 + 42, MOD = 1e9 + 7;

bool ans[N];
Node node[N];
set<int> win[N];
vector<int> adj[N];
int n, m, see = 1, par[N], sum[N], lastSeen[N];

int F(int i) {
    if(par[i] == i)
        return i;
    return par[i] = F(par[i]);
}

void U(int a, int b) {
    a = F(a), b = F(b);
    if(a == b)
        return;
    if(win[a].size() > win[b].size())
        swap(a, b);
    par[a] = b;
    sum[b] += sum[a];
    for(int i : win[a])
        win[b].insert(i);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        node[i].id = i;
        cin >> node[i].nbHab;

        par[i] = i;
        win[i].insert(i);
        sum[i] = node[i].nbHab;
    }

    for(int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        a--, b--;
        if(a > b) swap(a, b);
        if(node[a].nbHab > node[b].nbHab) swap(a, b);

        adj[b].push_back(a);
    }

    sort(node, node + n,
    [](Node a, Node b) {
        if(a.nbHab == b.nbHab)
            return a.id < b.id;
        return a.nbHab < b.nbHab;
    });

    for(int i = 0; i < n; i++) {
        see++;
        for(int j : adj[node[i].id]) {
            j = F(j);
            if(j == F(node[i].id) || lastSeen[j] != see) {
                lastSeen[j] = see;

                if(sum[j] >= node[i].nbHab)
                    U(j, node[i].id);
            }
        }
    }
    for(int i : win[F(node[n-1].id)])
        ans[i] = true;
    for(int i = 0; i < n; i++)
        cout << ans[i];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 9 ms 14432 KB Output is correct
4 Incorrect 10 ms 14548 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 9 ms 14420 KB Output is correct
3 Incorrect 154 ms 42120 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Incorrect 170 ms 39172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Incorrect 178 ms 39652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 9 ms 14432 KB Output is correct
4 Incorrect 10 ms 14548 KB Output isn't correct
5 Halted 0 ms 0 KB -