답안 #1011940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011940 2024-07-01T11:25:15 Z LucaIlie 슈퍼트리 잇기 (IOI20_supertrees) C++17
96 / 100
164 ms 24404 KB
#include "supertrees.h"
#include <vector>
#include <iostream>
using namespace std;
vector<vector<int>> answer;
#define nmax 1000
int daddy[nmax], daddy_cyc[nmax];
vector<int> cyc[nmax];

int find_daddy( int a ) {
    int x;
    if( daddy[a] == a )
        return a;
    x = find_daddy( daddy[a] );
    daddy[a] = x;
    return x;
}

void marry_daddy( int a, int b ) {
    int x, y;
    x = find_daddy( a );
    y = find_daddy( b );
    daddy[x] = y;
}

int find_daddy_cyc( int a ) {
    int x;
    if( daddy_cyc[a] == a )
        return a;
    x = find_daddy_cyc( daddy_cyc[a] );
    daddy_cyc[a] = x;
    return x;
}

void marry_daddy_cyc( int a, int b ) {
    int x, y;
    x = find_daddy_cyc( a );
    y = find_daddy_cyc( b );
    daddy_cyc[x] = y;
}

int construct( vector<vector<int>> p) {
    int n = p.size();
    for (int i = 0; i < n; i++) {
        vector<int> row;
        row.resize(n);
        answer.push_back(row);
    }

    int i, j;
    bool ok = true;
    for( i = 0; i < n; i++ )
        daddy[i] = daddy_cyc[i] = i;
    for( i = 0; i < n; i++ ) {
        for( j = 0; j < n; j++ )
            if( p[i][j] == 1 )
                marry_daddy( i, j );
    }
    for( i = 0; i < n; i++ ) {
        for( j = 0; j < n; j++ )
            if( p[i][j] != 1 && find_daddy(i) == find_daddy(j) )
                ok = false;
    }
    if( !ok )
        return 0;
    for( i = 0; i < n; i++ )
        if( find_daddy(i) != i ) {
            answer[i][find_daddy(i)] = 1;
            answer[find_daddy(i)][i] = 1;
        }

    for( i = 0; i < n; i++ ) {
        for( j = 0; j < n; j++ )
            if( p[i][j] == 2 )
                marry_daddy_cyc(find_daddy(i), find_daddy(j) );
    }
    for( i = 0; i < n; i++ ) {
        for( j = 0; j < n; j++ )
            if( p[i][j] < 2 && find_daddy(i) != find_daddy(j) && find_daddy_cyc(find_daddy(i)) == find_daddy_cyc(find_daddy(j)) )
                ok = false;
    }
    if( !ok )
        return 0;

    for( i = 0; i < n; i++ ) {
        if( find_daddy_cyc(i) != i )
            cyc[find_daddy_cyc(i)].push_back(i);
    }

    for( i = 0; i < n; i++ ) {
        if( cyc[i].size() == 1 )
            ok = false;
        if( cyc[i].size() >= 2 ) {
            for( j = 0; j < cyc[i].size() - 1; j++ ) {
                answer[cyc[i][j+1]][cyc[i][j]] = 1;
                answer[cyc[i][j]][cyc[i][j+1]] = 1;
            }
            answer[i][cyc[i][0]] = 1;
            answer[cyc[i][0]][i] = 1;
            answer[i][cyc[i][j]] = 1;
            answer[cyc[i][j]][i] = 1;
        }
    }
    if( !ok )
        return 0;
    build(answer);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:94:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |             for( j = 0; j < cyc[i].size() - 1; j++ ) {
      |                         ~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 5 ms 1212 KB Output is correct
7 Correct 115 ms 24064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 5 ms 1212 KB Output is correct
7 Correct 115 ms 24064 KB Output is correct
8 Correct 1 ms 344 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 5 ms 1372 KB Output is correct
13 Correct 128 ms 23972 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 984 KB Output is correct
17 Correct 69 ms 14164 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 54 ms 6364 KB Output is correct
21 Correct 119 ms 24148 KB Output is correct
22 Correct 125 ms 23996 KB Output is correct
23 Correct 164 ms 24144 KB Output is correct
24 Correct 114 ms 24152 KB Output is correct
25 Correct 52 ms 14164 KB Output is correct
26 Correct 50 ms 14228 KB Output is correct
27 Correct 128 ms 24100 KB Output is correct
28 Correct 115 ms 24148 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1372 KB Output is correct
9 Correct 115 ms 23952 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 5 ms 1396 KB Output is correct
13 Correct 126 ms 24404 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 70 ms 14164 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 464 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 29 ms 6268 KB Output is correct
22 Correct 128 ms 24144 KB Output is correct
23 Correct 150 ms 23976 KB Output is correct
24 Correct 121 ms 24148 KB Output is correct
25 Correct 53 ms 14164 KB Output is correct
26 Correct 59 ms 14164 KB Output is correct
27 Correct 108 ms 24144 KB Output is correct
28 Correct 110 ms 24016 KB Output is correct
29 Correct 51 ms 14164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 29 ms 6228 KB Output is correct
5 Correct 121 ms 24144 KB Output is correct
6 Correct 112 ms 24148 KB Output is correct
7 Correct 117 ms 24144 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 27 ms 6220 KB Output is correct
10 Correct 104 ms 24144 KB Output is correct
11 Correct 129 ms 24164 KB Output is correct
12 Correct 116 ms 24148 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 30 ms 6356 KB Output is correct
17 Correct 119 ms 24144 KB Output is correct
18 Correct 115 ms 24144 KB Output is correct
19 Correct 120 ms 23976 KB Output is correct
20 Correct 108 ms 24144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 5 ms 1212 KB Output is correct
7 Correct 115 ms 24064 KB Output is correct
8 Correct 1 ms 344 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 5 ms 1372 KB Output is correct
13 Correct 128 ms 23972 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 984 KB Output is correct
17 Correct 69 ms 14164 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 54 ms 6364 KB Output is correct
21 Correct 119 ms 24148 KB Output is correct
22 Correct 125 ms 23996 KB Output is correct
23 Correct 164 ms 24144 KB Output is correct
24 Correct 114 ms 24152 KB Output is correct
25 Correct 52 ms 14164 KB Output is correct
26 Correct 50 ms 14228 KB Output is correct
27 Correct 128 ms 24100 KB Output is correct
28 Correct 115 ms 24148 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1372 KB Output is correct
37 Correct 115 ms 23952 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 5 ms 1396 KB Output is correct
41 Correct 126 ms 24404 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 70 ms 14164 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 464 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 29 ms 6268 KB Output is correct
50 Correct 128 ms 24144 KB Output is correct
51 Correct 150 ms 23976 KB Output is correct
52 Correct 121 ms 24148 KB Output is correct
53 Correct 53 ms 14164 KB Output is correct
54 Correct 59 ms 14164 KB Output is correct
55 Correct 108 ms 24144 KB Output is correct
56 Correct 110 ms 24016 KB Output is correct
57 Correct 51 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 63 ms 14160 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 27 ms 6432 KB Output is correct
66 Correct 51 ms 14024 KB Output is correct
67 Correct 55 ms 14024 KB Output is correct
68 Correct 59 ms 14164 KB Output is correct
69 Correct 51 ms 14160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 5 ms 1212 KB Output is correct
7 Correct 115 ms 24064 KB Output is correct
8 Correct 1 ms 344 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 5 ms 1372 KB Output is correct
13 Correct 128 ms 23972 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 984 KB Output is correct
17 Correct 69 ms 14164 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 54 ms 6364 KB Output is correct
21 Correct 119 ms 24148 KB Output is correct
22 Correct 125 ms 23996 KB Output is correct
23 Correct 164 ms 24144 KB Output is correct
24 Correct 114 ms 24152 KB Output is correct
25 Correct 52 ms 14164 KB Output is correct
26 Correct 50 ms 14228 KB Output is correct
27 Correct 128 ms 24100 KB Output is correct
28 Correct 115 ms 24148 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1372 KB Output is correct
37 Correct 115 ms 23952 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 5 ms 1396 KB Output is correct
41 Correct 126 ms 24404 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 70 ms 14164 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 464 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 29 ms 6268 KB Output is correct
50 Correct 128 ms 24144 KB Output is correct
51 Correct 150 ms 23976 KB Output is correct
52 Correct 121 ms 24148 KB Output is correct
53 Correct 53 ms 14164 KB Output is correct
54 Correct 59 ms 14164 KB Output is correct
55 Correct 108 ms 24144 KB Output is correct
56 Correct 110 ms 24016 KB Output is correct
57 Correct 51 ms 14164 KB Output is correct
58 Correct 0 ms 600 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 29 ms 6228 KB Output is correct
62 Correct 121 ms 24144 KB Output is correct
63 Correct 112 ms 24148 KB Output is correct
64 Correct 117 ms 24144 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 27 ms 6220 KB Output is correct
67 Correct 104 ms 24144 KB Output is correct
68 Correct 129 ms 24164 KB Output is correct
69 Correct 116 ms 24148 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 30 ms 6356 KB Output is correct
74 Correct 119 ms 24144 KB Output is correct
75 Correct 115 ms 24144 KB Output is correct
76 Correct 120 ms 23976 KB Output is correct
77 Correct 108 ms 24144 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 63 ms 14160 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 27 ms 6432 KB Output is correct
86 Correct 51 ms 14024 KB Output is correct
87 Correct 55 ms 14024 KB Output is correct
88 Correct 59 ms 14164 KB Output is correct
89 Correct 51 ms 14160 KB Output is correct
90 Correct 1 ms 464 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 3 ms 860 KB Output is correct
93 Correct 62 ms 14248 KB Output is correct
94 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -