Submission #519554

# Submission time Handle Problem Language Result Execution time Memory
519554 2022-01-26T16:23:20 Z LucaIlie Connecting Supertrees (IOI20_supertrees) C++17
40 / 100
202 ms 22724 KB
#include <iostream>
#include <vector>
#include "supertrees.h"

#define MAX_N 1000

using namespace std;

struct dsu {
    int n;
    int sef[MAX_N];

    void init( int x ) {
        int i;

        n = x;
        for ( i = 0; i < n; i++ )
            sef[i] = i;
    }

    int find( int x ) {
        if ( sef[x] != x )
            sef[x] = find( sef[x] );
        return sef[x];
    }

    void unionn( int x, int y ) {
        x = find( x );
        y = find( y );
        sef[y] = x;
    }
};

int construct( vector <vector <int>> p ) {
    int n, x, y, i, j;
    dsu forest1, forest2;
    vector <int> f1[MAX_N], f2[MAX_N];

    n = p.size();
    vector <vector <int>> b( n );
    forest1.init( n );
    forest2.init( n );


    for ( x = 0; x < n; x++ ) {
        for ( y = 0; y < n; y++ ) {
            if ( p[x][y] >= 1 )
                forest1.unionn( x, y );
            if ( p[x][y] >= 2 )
                forest2.unionn( x, y );
        }
    }

    for ( x = 0; x < n; x++ ) {
        f1[forest1.find( x )].push_back( x );
        f2[forest2.find( x )].push_back( x );
    }

    for ( i = 0; i < n; i++ ) {
        for ( j = 0; j < n; j++ )
            b[i].push_back( 0 );
    }

    /// 1
    for ( x = 0; x < n; x++ ) {
        if ( f1[x].size() > 1 ) {
            for ( i = 0; i < f1[x].size(); i++ ) {
                for ( j = i + 1; j < f1[x].size(); j++ ) {
                    if ( p[f1[x][i]][f1[x][j]] == 0 )
                        return 0;
                }
            }
            for ( i = 0; i < f1[x].size() - 1; i++ ) {
                b[f1[x][i]][f1[x][i + 1]] = 1;
                b[f1[x][i + 1]][f1[x][i]] = 1;
            }
        }
    }

    /// 2
    for ( x = 0; x < n; x++ ) {
        if ( f2[x].size() > 1 ) {
            for ( i = 0; i < f2[x].size(); i++ ) {
                for ( j = i + 1; j < f2[x].size(); j++ ) {
                    if ( p[f2[x][i]][f2[x][j]] <= 1 )
                        return 0;
                }
            }
            if ( f2[x].size() <= 2 )
                return 0;
            b[f2[x][0]][f2[x][f2[x].size() - 1]] = 1;
            b[f2[x][f2[x].size() - 1]][f2[x][0]] = 1;
        }
    }

    build( b );

    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:67:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |             for ( i = 0; i < f1[x].size(); i++ ) {
      |                          ~~^~~~~~~~~~~~~~
supertrees.cpp:68:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |                 for ( j = i + 1; j < f1[x].size(); j++ ) {
      |                                  ~~^~~~~~~~~~~~~~
supertrees.cpp:73:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |             for ( i = 0; i < f1[x].size() - 1; i++ ) {
      |                          ~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:83:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |             for ( i = 0; i < f2[x].size(); i++ ) {
      |                          ~~^~~~~~~~~~~~~~
supertrees.cpp:84:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |                 for ( j = i + 1; j < f2[x].size(); j++ ) {
      |                                  ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 180 ms 22152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 180 ms 22152 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 8 ms 1228 KB Output is correct
13 Correct 174 ms 22164 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 81 ms 12296 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 43 ms 5832 KB Output is correct
21 Correct 173 ms 22300 KB Output is correct
22 Correct 174 ms 22208 KB Output is correct
23 Correct 194 ms 22184 KB Output is correct
24 Correct 175 ms 22208 KB Output is correct
25 Correct 72 ms 12280 KB Output is correct
26 Correct 66 ms 12228 KB Output is correct
27 Correct 192 ms 22152 KB Output is correct
28 Correct 174 ms 22188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 288 KB Output is correct
2 Correct 2 ms 292 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 8 ms 1292 KB Output is correct
9 Correct 179 ms 22576 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 10 ms 1356 KB Output is correct
13 Correct 202 ms 22504 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 4 ms 872 KB Output is correct
17 Correct 118 ms 12616 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 49 ms 5976 KB Output is correct
22 Correct 197 ms 22428 KB Output is correct
23 Correct 196 ms 22464 KB Output is correct
24 Correct 197 ms 22460 KB Output is correct
25 Correct 71 ms 12752 KB Output is correct
26 Correct 71 ms 12612 KB Output is correct
27 Correct 172 ms 22456 KB Output is correct
28 Correct 188 ms 22524 KB Output is correct
29 Correct 68 ms 12616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 46 ms 6044 KB Output is correct
5 Correct 180 ms 22724 KB Output is correct
6 Correct 186 ms 22620 KB Output is correct
7 Correct 191 ms 22656 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 44 ms 5956 KB Output is correct
10 Correct 178 ms 22592 KB Output is correct
11 Correct 176 ms 22608 KB Output is correct
12 Correct 192 ms 22560 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Incorrect 1 ms 332 KB Answer gives possible 0 while actual possible 1
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 180 ms 22152 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 8 ms 1228 KB Output is correct
13 Correct 174 ms 22164 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 81 ms 12296 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 43 ms 5832 KB Output is correct
21 Correct 173 ms 22300 KB Output is correct
22 Correct 174 ms 22208 KB Output is correct
23 Correct 194 ms 22184 KB Output is correct
24 Correct 175 ms 22208 KB Output is correct
25 Correct 72 ms 12280 KB Output is correct
26 Correct 66 ms 12228 KB Output is correct
27 Correct 192 ms 22152 KB Output is correct
28 Correct 174 ms 22188 KB Output is correct
29 Correct 0 ms 288 KB Output is correct
30 Correct 2 ms 292 KB Output is correct
31 Correct 1 ms 288 KB Output is correct
32 Correct 1 ms 288 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 292 KB Output is correct
36 Correct 8 ms 1292 KB Output is correct
37 Correct 179 ms 22576 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 10 ms 1356 KB Output is correct
41 Correct 202 ms 22504 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 292 KB Output is correct
44 Correct 4 ms 872 KB Output is correct
45 Correct 118 ms 12616 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 49 ms 5976 KB Output is correct
50 Correct 197 ms 22428 KB Output is correct
51 Correct 196 ms 22464 KB Output is correct
52 Correct 197 ms 22460 KB Output is correct
53 Correct 71 ms 12752 KB Output is correct
54 Correct 71 ms 12612 KB Output is correct
55 Correct 172 ms 22456 KB Output is correct
56 Correct 188 ms 22524 KB Output is correct
57 Correct 68 ms 12616 KB Output is correct
58 Correct 0 ms 296 KB Output is correct
59 Correct 0 ms 332 KB Output is correct
60 Correct 4 ms 844 KB Output is correct
61 Correct 85 ms 12612 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 0 ms 332 KB Output is correct
65 Incorrect 19 ms 3508 KB Answer gives possible 0 while actual possible 1
66 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 180 ms 22152 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 8 ms 1228 KB Output is correct
13 Correct 174 ms 22164 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 81 ms 12296 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 43 ms 5832 KB Output is correct
21 Correct 173 ms 22300 KB Output is correct
22 Correct 174 ms 22208 KB Output is correct
23 Correct 194 ms 22184 KB Output is correct
24 Correct 175 ms 22208 KB Output is correct
25 Correct 72 ms 12280 KB Output is correct
26 Correct 66 ms 12228 KB Output is correct
27 Correct 192 ms 22152 KB Output is correct
28 Correct 174 ms 22188 KB Output is correct
29 Correct 0 ms 288 KB Output is correct
30 Correct 2 ms 292 KB Output is correct
31 Correct 1 ms 288 KB Output is correct
32 Correct 1 ms 288 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 292 KB Output is correct
36 Correct 8 ms 1292 KB Output is correct
37 Correct 179 ms 22576 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 10 ms 1356 KB Output is correct
41 Correct 202 ms 22504 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 292 KB Output is correct
44 Correct 4 ms 872 KB Output is correct
45 Correct 118 ms 12616 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 49 ms 5976 KB Output is correct
50 Correct 197 ms 22428 KB Output is correct
51 Correct 196 ms 22464 KB Output is correct
52 Correct 197 ms 22460 KB Output is correct
53 Correct 71 ms 12752 KB Output is correct
54 Correct 71 ms 12612 KB Output is correct
55 Correct 172 ms 22456 KB Output is correct
56 Correct 188 ms 22524 KB Output is correct
57 Correct 68 ms 12616 KB Output is correct
58 Correct 1 ms 288 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 46 ms 6044 KB Output is correct
62 Correct 180 ms 22724 KB Output is correct
63 Correct 186 ms 22620 KB Output is correct
64 Correct 191 ms 22656 KB Output is correct
65 Correct 0 ms 332 KB Output is correct
66 Correct 44 ms 5956 KB Output is correct
67 Correct 178 ms 22592 KB Output is correct
68 Correct 176 ms 22608 KB Output is correct
69 Correct 192 ms 22560 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 0 ms 332 KB Output is correct
72 Incorrect 1 ms 332 KB Answer gives possible 0 while actual possible 1
73 Halted 0 ms 0 KB -