답안 #1054959

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054959 2024-08-12T13:21:51 Z c2zi6 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
111 ms 28092 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "supertrees.h"

VVI comps(VVI s, bool t0, bool t1, bool t2) {
    /*transformations*/
    int n = s.size();
    rep(i, n) rep(j, n) {
        if (s[i][j] == 0) s[i][j] = t0;
        else if (s[i][j] == 1) s[i][j] = t1;
        else if (s[i][j] == 2) s[i][j] = t2;
    }
    sort(all(s));
    VVI ret;
    for (int i = 0; i < n; i++) {
        if (i == 0 || s[i] != s[i-1]) {
            if (i) rep(j, n) {
                if (s[i][j] && s[i-1][j]) {
                    return VVI();
                }
            }
            ret.pb(VI());
            rep(j, n) if (s[i][j]) ret.back().pb(j);
        }
    }
    return ret;
}

int construct(VVI p) {
    int n = p.size();
    VVI comp = comps(p, 0, 1, 1);
    if (comp.size() == 0) return 0;
    VVI ans(n, VI(n));
    /*for (VI vec : comp) {*/
    /*    replr(i, 1, vec.size()-1) {*/
    /*        ans[vec[0]][vec[i]] = true;*/
    /*        ans[vec[i]][vec[0]] = true;*/
    /*    }*/
    /*}*/
    VVVI a;
    for (VI vec : comp) {
        int s = vec.size();
        a.pb(VVI(s, VI(s)));
        rep(i, s) {
            rep(j, s) {
                int x = vec[i];
                int y = vec[j];
                a.back()[i][j] = p[x][y];
            }
        }
    }

    VPI edges;
    rep(c, comp.size()) {
        int n = comp[c].size();
        VVI p = a[c];


        VVI trees = comps(p, 0, 1, 0);
        if (trees.size() == 0) return 0;
        for (VI& v : trees) for (int& x : v) x = comp[c][x];

        /*cout << "COMPONENT ";*/
        /*for (int x : comp[c]) cout << x << " "; cout << endl;*/
        /*rep(i, n) {*/
        /*    rep(j, n) cout << p[i][j] << " ";*/
        /*    cout << endl;*/
        /*}*/
        /*for (VI v : trees) {*/
        /*    cout << "   TREE ";*/
        /*    for (int x : v) cout << x << " ";*/
        /*    cout << endl;*/
        /*}*/

        VI roots;
        for (VI v : trees) {
            int r = v[0];
            roots.pb(r);
            replr(i, 1, v.size()-1) {
                edges.pb({r, v[i]});
            }
        }
        int r = roots.size();
        if (r == 1) continue;
        if (r == 2) return 0;
        rep(i, r) {
            edges.pb({roots[i], roots[(i+1)%r]});
        }
    }
    for (auto[u, v] : edges) {
        ans[u][v] = ans[v][u] = 1;
        /*cout << u << " " << v << endl;*/
    }
    build(ans);
	return 1;
}


Compilation message

supertrees.cpp: In function 'int construct(VVI)':
supertrees.cpp:84:13: warning: unused variable 'n' [-Wunused-variable]
   84 |         int n = comp[c].size();
      |             ^
supertrees.cpp:119:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  119 |     for (auto[u, v] : edges) {
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 106 ms 28092 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 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 106 ms 28092 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1368 KB Output is correct
13 Correct 101 ms 24152 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 932 KB Output is correct
17 Correct 49 ms 14220 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 6260 KB Output is correct
21 Correct 95 ms 24404 KB Output is correct
22 Correct 93 ms 24144 KB Output is correct
23 Correct 107 ms 25932 KB Output is correct
24 Correct 101 ms 24148 KB Output is correct
25 Correct 44 ms 14172 KB Output is correct
26 Correct 42 ms 14220 KB Output is correct
27 Correct 103 ms 26008 KB Output is correct
28 Correct 97 ms 24144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 98 ms 23924 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1368 KB Output is correct
13 Correct 110 ms 28040 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 48 ms 14012 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 25 ms 6324 KB Output is correct
22 Correct 110 ms 24408 KB Output is correct
23 Correct 97 ms 24200 KB Output is correct
24 Correct 111 ms 25992 KB Output is correct
25 Correct 48 ms 14164 KB Output is correct
26 Correct 44 ms 14160 KB Output is correct
27 Correct 95 ms 24144 KB Output is correct
28 Correct 105 ms 26124 KB Output is correct
29 Correct 45 ms 14164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 26 ms 6360 KB Output is correct
5 Correct 96 ms 24504 KB Output is correct
6 Correct 93 ms 24148 KB Output is correct
7 Correct 106 ms 26048 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 24 ms 6272 KB Output is correct
10 Correct 101 ms 24404 KB Output is correct
11 Correct 95 ms 24072 KB Output is correct
12 Correct 104 ms 25940 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 23 ms 6268 KB Output is correct
17 Correct 96 ms 24404 KB Output is correct
18 Correct 98 ms 24456 KB Output is correct
19 Correct 95 ms 24324 KB Output is correct
20 Correct 106 ms 24140 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 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 106 ms 28092 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1368 KB Output is correct
13 Correct 101 ms 24152 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 932 KB Output is correct
17 Correct 49 ms 14220 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 6260 KB Output is correct
21 Correct 95 ms 24404 KB Output is correct
22 Correct 93 ms 24144 KB Output is correct
23 Correct 107 ms 25932 KB Output is correct
24 Correct 101 ms 24148 KB Output is correct
25 Correct 44 ms 14172 KB Output is correct
26 Correct 42 ms 14220 KB Output is correct
27 Correct 103 ms 26008 KB Output is correct
28 Correct 97 ms 24144 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 436 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 4 ms 1372 KB Output is correct
37 Correct 98 ms 23924 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 4 ms 1368 KB Output is correct
41 Correct 110 ms 28040 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 48 ms 14012 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 25 ms 6324 KB Output is correct
50 Correct 110 ms 24408 KB Output is correct
51 Correct 97 ms 24200 KB Output is correct
52 Correct 111 ms 25992 KB Output is correct
53 Correct 48 ms 14164 KB Output is correct
54 Correct 44 ms 14160 KB Output is correct
55 Correct 95 ms 24144 KB Output is correct
56 Correct 105 ms 26124 KB Output is correct
57 Correct 45 ms 14164 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 856 KB Output is correct
61 Correct 55 ms 14084 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 24 ms 6272 KB Output is correct
66 Correct 44 ms 14164 KB Output is correct
67 Correct 57 ms 14160 KB Output is correct
68 Correct 42 ms 14160 KB Output is correct
69 Correct 52 ms 14164 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 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 106 ms 28092 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1368 KB Output is correct
13 Correct 101 ms 24152 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 932 KB Output is correct
17 Correct 49 ms 14220 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 6260 KB Output is correct
21 Correct 95 ms 24404 KB Output is correct
22 Correct 93 ms 24144 KB Output is correct
23 Correct 107 ms 25932 KB Output is correct
24 Correct 101 ms 24148 KB Output is correct
25 Correct 44 ms 14172 KB Output is correct
26 Correct 42 ms 14220 KB Output is correct
27 Correct 103 ms 26008 KB Output is correct
28 Correct 97 ms 24144 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 436 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 4 ms 1372 KB Output is correct
37 Correct 98 ms 23924 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 4 ms 1368 KB Output is correct
41 Correct 110 ms 28040 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 48 ms 14012 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 25 ms 6324 KB Output is correct
50 Correct 110 ms 24408 KB Output is correct
51 Correct 97 ms 24200 KB Output is correct
52 Correct 111 ms 25992 KB Output is correct
53 Correct 48 ms 14164 KB Output is correct
54 Correct 44 ms 14160 KB Output is correct
55 Correct 95 ms 24144 KB Output is correct
56 Correct 105 ms 26124 KB Output is correct
57 Correct 45 ms 14164 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 26 ms 6360 KB Output is correct
62 Correct 96 ms 24504 KB Output is correct
63 Correct 93 ms 24148 KB Output is correct
64 Correct 106 ms 26048 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 24 ms 6272 KB Output is correct
67 Correct 101 ms 24404 KB Output is correct
68 Correct 95 ms 24072 KB Output is correct
69 Correct 104 ms 25940 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 23 ms 6268 KB Output is correct
74 Correct 96 ms 24404 KB Output is correct
75 Correct 98 ms 24456 KB Output is correct
76 Correct 95 ms 24324 KB Output is correct
77 Correct 106 ms 24140 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 3 ms 856 KB Output is correct
81 Correct 55 ms 14084 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 24 ms 6272 KB Output is correct
86 Correct 44 ms 14164 KB Output is correct
87 Correct 57 ms 14160 KB Output is correct
88 Correct 42 ms 14160 KB Output is correct
89 Correct 52 ms 14164 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 2 ms 860 KB Output is correct
93 Correct 48 ms 14212 KB Output is correct
94 Correct 0 ms 344 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 12 ms 3716 KB Output is correct
98 Correct 44 ms 14164 KB Output is correct
99 Correct 44 ms 14084 KB Output is correct
100 Correct 56 ms 14072 KB Output is correct
101 Correct 53 ms 14164 KB Output is correct
102 Correct 42 ms 14092 KB Output is correct
103 Correct 43 ms 14084 KB Output is correct
104 Correct 74 ms 14164 KB Output is correct
105 Correct 59 ms 13992 KB Output is correct