답안 #1032879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032879 2024-07-24T10:20:43 Z Zicrus 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
151 ms 23632 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;

typedef long long ll;

vector<ll> lnk1, lnk2;

ll find1(ll a) {
    if (lnk1[a] != a) lnk1[a] = find1(lnk1[a]);
    return lnk1[a];
}

ll find2(ll a) {
    if (lnk2[a] != a) lnk2[a] = find2(lnk2[a]);
    return lnk2[a];
}

void unite1(ll a, ll b) {
    a = find1(a); b = find1(b);
    lnk1[b] = a;
}

void unite2(ll a, ll b) {
    a = find2(a); b = find2(b);
    lnk2[b] = a;
}

int construct(vector<vector<int>> p) {
    ll n = p.size();
    lnk1 = vector<ll>(p.size());
    lnk2 = vector<ll>(p.size());
    for (int i = 0; i < n; i++) lnk1[i] = lnk2[i] = i;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (p[i][j] == 3) return 0;
            if (p[i][j] == 2) unite2(i, j);
            if (p[i][j] == 1) unite1(i, j);
        }
    }

    vector<set<ll>> clubs1(n), clubs2(n);
    for (int i = 0; i < n; i++) {
        clubs1[find1(i)].insert(i);
        clubs2[find2(i)].insert(find1(i));
    }

    vector<vector<int>> res(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        if (clubs2[i].size() > 1) {
            ll prev = *--clubs2[i].end();
            for (auto &e : clubs2[i]) {
                res[prev][e] = 1;
                res[e][prev] = 1;
                unite2(e, prev);
                prev = e;
            }
        }
        if (clubs1[i].size() > 1) {
            ll prev = -1;
            for (auto &e : clubs1[i]) {
                if (prev != -1) {
                    res[prev][e] = 1;
                    res[e][prev] = 1;
                    unite2(e, prev);
                }
                prev = e;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (p[i][j] == 0 && find2(i) == find2(j)) return 0;
            if (p[i][j] == 2 && find1(i) == find1(j)) return 0;
        }
    }

    build(res);
    return 1;
}
# 결과 실행 시간 메모리 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 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1364 KB Output is correct
7 Correct 118 ms 22356 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1364 KB Output is correct
7 Correct 118 ms 22356 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 117 ms 22260 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 60 ms 12368 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5892 KB Output is correct
21 Correct 125 ms 22296 KB Output is correct
22 Correct 127 ms 22356 KB Output is correct
23 Correct 130 ms 22300 KB Output is correct
24 Correct 119 ms 22352 KB Output is correct
25 Correct 58 ms 12312 KB Output is correct
26 Correct 50 ms 12368 KB Output is correct
27 Correct 135 ms 22232 KB Output is correct
28 Correct 113 ms 22356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 30 ms 6396 KB Output is correct
5 Correct 151 ms 23472 KB Output is correct
6 Correct 116 ms 23516 KB Output is correct
7 Correct 130 ms 23632 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 29 ms 6476 KB Output is correct
10 Correct 129 ms 23632 KB Output is correct
11 Correct 118 ms 23572 KB Output is correct
12 Correct 128 ms 23632 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 30 ms 6272 KB Output is correct
17 Correct 122 ms 23460 KB Output is correct
18 Correct 132 ms 23484 KB Output is correct
19 Correct 121 ms 23576 KB Output is correct
20 Correct 115 ms 23480 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1364 KB Output is correct
7 Correct 118 ms 22356 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 117 ms 22260 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 60 ms 12368 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5892 KB Output is correct
21 Correct 125 ms 22296 KB Output is correct
22 Correct 127 ms 22356 KB Output is correct
23 Correct 130 ms 22300 KB Output is correct
24 Correct 119 ms 22352 KB Output is correct
25 Correct 58 ms 12312 KB Output is correct
26 Correct 50 ms 12368 KB Output is correct
27 Correct 135 ms 22232 KB Output is correct
28 Correct 113 ms 22356 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 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 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1364 KB Output is correct
7 Correct 118 ms 22356 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 117 ms 22260 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 60 ms 12368 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5892 KB Output is correct
21 Correct 125 ms 22296 KB Output is correct
22 Correct 127 ms 22356 KB Output is correct
23 Correct 130 ms 22300 KB Output is correct
24 Correct 119 ms 22352 KB Output is correct
25 Correct 58 ms 12312 KB Output is correct
26 Correct 50 ms 12368 KB Output is correct
27 Correct 135 ms 22232 KB Output is correct
28 Correct 113 ms 22356 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -