답안 #1047611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047611 2024-08-07T14:22:27 Z idas 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
112 ms 24148 KB
#include "supertrees.h"
#include "bits/stdc++.h"
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define sz(x) ((int)((x).size()))
#define pb push_back

using namespace std;
typedef long long ll;
typedef vector<int> vi;

const int MxN=1e3+10;
int n, par[MxN], cyc[MxN];
bool v[MxN];

int fnd(int u) {
    return par[u]=par[u]==u?u:fnd(par[u]);
}

void mrg(int a, int b) {
    a=fnd(a); b=fnd(b);
    if(a==b) return;
    par[a]=b;
}

int construct(std::vector<std::vector<int>> p) {
    n=sz(p);

    FOR(i, 0, n) par[i]=i;

    vector b(n, vector(n, 0));
    FOR(i, 0, n) {
        FOR(j, 0, n) {
            if(fnd(i)==fnd(j)) continue;
            if(p[i][j]==1) {
                b[i][j]=b[j][i]=1;
                mrg(i, j);
            }
        }
    }

    vector used(n, false);
    FOR(i, 0, n) {
        int u=fnd(i);
        if(used[u]) continue;

        used[u]=true;
        cyc[u]=i;

        int cn=1, lst=u, frst=u;
        FOR(j, 0, n) {
            int w=fnd(j);
            if(used[w]) continue;

            if(p[u][w]==2) {
                used[w]=true;
                cyc[w]=i;
                cn++;

                b[lst][w]=b[w][lst]=1;
                lst=w;
            }
        }
        b[lst][frst]=b[frst][lst]=1;

        if(cn==2) {
            return 0;
        }
    }

    bool ok=true;
    FOR(i, 0, n) {
        FOR(j, i+1, n) {
            int u=fnd(i), w=fnd(j);
            if(u==w) ok&=p[i][j]==1;
            else if(cyc[u]==cyc[w]) ok&=p[i][j]==2;
            else ok&=p[i][j]==0;
        }
    }

    FOR(i, 0, n) b[i][i]=0;

    if(!ok) return 0;

    build(b);

    return 1;
}
/*
Example 1:
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1

Example 2:
2
1 0
0 1

Example 3:
2
1 3
3 1

5
1 1 2 2 2
1 1 2 2 2
2 2 1 2 2
2 2 2 1 1
2 2 2 1 1
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1116 KB Output is correct
7 Correct 92 ms 22120 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 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 1116 KB Output is correct
7 Correct 92 ms 22120 KB Output is correct
8 Correct 0 ms 356 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 4 ms 1116 KB Output is correct
13 Correct 94 ms 22044 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 47 ms 14228 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 6276 KB Output is correct
21 Correct 105 ms 24148 KB Output is correct
22 Correct 108 ms 23948 KB Output is correct
23 Correct 103 ms 24144 KB Output is correct
24 Correct 99 ms 24144 KB Output is correct
25 Correct 59 ms 14072 KB Output is correct
26 Correct 44 ms 14204 KB Output is correct
27 Correct 101 ms 24148 KB Output is correct
28 Correct 98 ms 24068 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 4 ms 1116 KB Output is correct
9 Correct 96 ms 22176 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 93 ms 22100 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 46 ms 12040 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 24 ms 5892 KB Output is correct
22 Correct 97 ms 22096 KB Output is correct
23 Correct 92 ms 22100 KB Output is correct
24 Correct 99 ms 22096 KB Output is correct
25 Correct 41 ms 12060 KB Output is correct
26 Correct 43 ms 12112 KB Output is correct
27 Correct 95 ms 22100 KB Output is correct
28 Correct 99 ms 22096 KB Output is correct
29 Correct 41 ms 12112 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 0 ms 348 KB Output is correct
4 Correct 24 ms 5852 KB Output is correct
5 Correct 96 ms 22096 KB Output is correct
6 Correct 100 ms 22100 KB Output is correct
7 Correct 112 ms 22040 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 27 ms 5712 KB Output is correct
10 Correct 103 ms 22100 KB Output is correct
11 Correct 105 ms 22100 KB Output is correct
12 Correct 98 ms 22044 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 23 ms 5872 KB Output is correct
17 Correct 94 ms 22044 KB Output is correct
18 Correct 98 ms 22100 KB Output is correct
19 Correct 93 ms 22084 KB Output is correct
20 Correct 98 ms 22028 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 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 1116 KB Output is correct
7 Correct 92 ms 22120 KB Output is correct
8 Correct 0 ms 356 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 4 ms 1116 KB Output is correct
13 Correct 94 ms 22044 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 47 ms 14228 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 6276 KB Output is correct
21 Correct 105 ms 24148 KB Output is correct
22 Correct 108 ms 23948 KB Output is correct
23 Correct 103 ms 24144 KB Output is correct
24 Correct 99 ms 24144 KB Output is correct
25 Correct 59 ms 14072 KB Output is correct
26 Correct 44 ms 14204 KB Output is correct
27 Correct 101 ms 24148 KB Output is correct
28 Correct 98 ms 24068 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 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 4 ms 1116 KB Output is correct
37 Correct 96 ms 22176 KB Output is correct
38 Correct 0 ms 600 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 4 ms 1116 KB Output is correct
41 Correct 93 ms 22100 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 856 KB Output is correct
45 Correct 46 ms 12040 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 24 ms 5892 KB Output is correct
50 Correct 97 ms 22096 KB Output is correct
51 Correct 92 ms 22100 KB Output is correct
52 Correct 99 ms 22096 KB Output is correct
53 Correct 41 ms 12060 KB Output is correct
54 Correct 43 ms 12112 KB Output is correct
55 Correct 95 ms 22100 KB Output is correct
56 Correct 99 ms 22096 KB Output is correct
57 Correct 41 ms 12112 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 860 KB Output is correct
61 Correct 50 ms 14092 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 25 ms 6396 KB Output is correct
66 Correct 44 ms 14216 KB Output is correct
67 Correct 49 ms 14160 KB Output is correct
68 Correct 44 ms 14000 KB Output is correct
69 Correct 41 ms 14164 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 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 1116 KB Output is correct
7 Correct 92 ms 22120 KB Output is correct
8 Correct 0 ms 356 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 4 ms 1116 KB Output is correct
13 Correct 94 ms 22044 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 47 ms 14228 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 6276 KB Output is correct
21 Correct 105 ms 24148 KB Output is correct
22 Correct 108 ms 23948 KB Output is correct
23 Correct 103 ms 24144 KB Output is correct
24 Correct 99 ms 24144 KB Output is correct
25 Correct 59 ms 14072 KB Output is correct
26 Correct 44 ms 14204 KB Output is correct
27 Correct 101 ms 24148 KB Output is correct
28 Correct 98 ms 24068 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 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 4 ms 1116 KB Output is correct
37 Correct 96 ms 22176 KB Output is correct
38 Correct 0 ms 600 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 4 ms 1116 KB Output is correct
41 Correct 93 ms 22100 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 856 KB Output is correct
45 Correct 46 ms 12040 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 24 ms 5892 KB Output is correct
50 Correct 97 ms 22096 KB Output is correct
51 Correct 92 ms 22100 KB Output is correct
52 Correct 99 ms 22096 KB Output is correct
53 Correct 41 ms 12060 KB Output is correct
54 Correct 43 ms 12112 KB Output is correct
55 Correct 95 ms 22100 KB Output is correct
56 Correct 99 ms 22096 KB Output is correct
57 Correct 41 ms 12112 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 24 ms 5852 KB Output is correct
62 Correct 96 ms 22096 KB Output is correct
63 Correct 100 ms 22100 KB Output is correct
64 Correct 112 ms 22040 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 27 ms 5712 KB Output is correct
67 Correct 103 ms 22100 KB Output is correct
68 Correct 105 ms 22100 KB Output is correct
69 Correct 98 ms 22044 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 23 ms 5872 KB Output is correct
74 Correct 94 ms 22044 KB Output is correct
75 Correct 98 ms 22100 KB Output is correct
76 Correct 93 ms 22084 KB Output is correct
77 Correct 98 ms 22028 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 3 ms 860 KB Output is correct
81 Correct 50 ms 14092 KB Output is correct
82 Correct 0 ms 344 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 25 ms 6396 KB Output is correct
86 Correct 44 ms 14216 KB Output is correct
87 Correct 49 ms 14160 KB Output is correct
88 Correct 44 ms 14000 KB Output is correct
89 Correct 41 ms 14164 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 344 KB Output is correct
92 Correct 2 ms 860 KB Output is correct
93 Correct 44 ms 14220 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 11 ms 3776 KB Output is correct
98 Correct 45 ms 14228 KB Output is correct
99 Correct 44 ms 14168 KB Output is correct
100 Correct 45 ms 14216 KB Output is correct
101 Correct 43 ms 14160 KB Output is correct
102 Correct 43 ms 14164 KB Output is correct
103 Correct 42 ms 14160 KB Output is correct
104 Correct 49 ms 14348 KB Output is correct
105 Correct 48 ms 14220 KB Output is correct