Submission #519544

# Submission time Handle Problem Language Result Execution time Memory
519544 2022-01-26T15:46:00 Z LucaIlie Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
194 ms 24208 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, a, x, y, i, j;
    dsu forest;
    vector <int> f[MAX_N];
 
    n = p.size();
    vector <vector <int>> b( n );
    forest.init( n );
 
 
    for ( x = 0; x < n; x++ ) {
        for ( y = 0; y < n; y++ ) {
            if ( p[x][y] > 0 )
                forest.unionn( x, y );
        }
    }
 
    for ( x = 0; x < n; x++ )
        f[forest.find( x )].push_back( x );
 
    for ( i = 0; i < n; i++ ) {
        for ( j = 0; j < n; j++ )
            b[i].push_back( 0 );
    }
    for ( x = 0; x < n; x++ ) {
        if ( f[x].size() ) {
            a = p[f[x][0]][f[x][f[x].size() - 1]];
            for ( i = 0; i < f[x].size(); i++ ) {
                for ( j = i + 1; j < f[x].size(); j++ ) {
                    if ( a != p[f[x][i]][f[x][j]] )
                        return 0;
                }
            }
            for ( i = 0; i < f[x].size() - 1; i++ ) {
                b[f[x][i]][f[x][i + 1]] = 1;
                b[f[x][i + 1]][f[x][i]] = 1;
            }
            if ( f[x].size() < a )
                return 0;
            if ( a == 2 ) {
                b[f[x][0]][f[x][f[x].size() - 1]] = 1;
                b[f[x][f[x].size() - 1]][f[x][0]] = 1;
            }
        }
    }
 
    build( b );
 
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:61:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |             for ( i = 0; i < f[x].size(); i++ ) {
      |                          ~~^~~~~~~~~~~~~
supertrees.cpp:62:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |                 for ( j = i + 1; j < f[x].size(); j++ ) {
      |                                  ~~^~~~~~~~~~~~~
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 < f[x].size() - 1; i++ ) {
      |                          ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:71:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   71 |             if ( f[x].size() < a )
      |                  ~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 7 ms 1204 KB Output is correct
7 Correct 187 ms 24056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 7 ms 1204 KB Output is correct
7 Correct 187 ms 24056 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 7 ms 1228 KB Output is correct
13 Correct 178 ms 24060 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 808 KB Output is correct
17 Correct 83 ms 14144 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 48 ms 6256 KB Output is correct
21 Correct 191 ms 24052 KB Output is correct
22 Correct 188 ms 24032 KB Output is correct
23 Correct 188 ms 24208 KB Output is correct
24 Correct 168 ms 24132 KB Output is correct
25 Correct 73 ms 14184 KB Output is correct
26 Correct 68 ms 14196 KB Output is correct
27 Correct 194 ms 24040 KB Output is correct
28 Correct 189 ms 24092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 268 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 288 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 42 ms 6252 KB Output is correct
5 Correct 170 ms 24060 KB Output is correct
6 Correct 187 ms 24088 KB Output is correct
7 Correct 191 ms 24076 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 42 ms 6252 KB Output is correct
10 Correct 192 ms 24140 KB Output is correct
11 Correct 164 ms 24040 KB Output is correct
12 Correct 178 ms 24172 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Incorrect 0 ms 204 KB Answer gives possible 0 while actual possible 1
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 7 ms 1204 KB Output is correct
7 Correct 187 ms 24056 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 7 ms 1228 KB Output is correct
13 Correct 178 ms 24060 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 808 KB Output is correct
17 Correct 83 ms 14144 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 48 ms 6256 KB Output is correct
21 Correct 191 ms 24052 KB Output is correct
22 Correct 188 ms 24032 KB Output is correct
23 Correct 188 ms 24208 KB Output is correct
24 Correct 168 ms 24132 KB Output is correct
25 Correct 73 ms 14184 KB Output is correct
26 Correct 68 ms 14196 KB Output is correct
27 Correct 194 ms 24040 KB Output is correct
28 Correct 189 ms 24092 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 268 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Incorrect 0 ms 288 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 7 ms 1204 KB Output is correct
7 Correct 187 ms 24056 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 7 ms 1228 KB Output is correct
13 Correct 178 ms 24060 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 808 KB Output is correct
17 Correct 83 ms 14144 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 48 ms 6256 KB Output is correct
21 Correct 191 ms 24052 KB Output is correct
22 Correct 188 ms 24032 KB Output is correct
23 Correct 188 ms 24208 KB Output is correct
24 Correct 168 ms 24132 KB Output is correct
25 Correct 73 ms 14184 KB Output is correct
26 Correct 68 ms 14196 KB Output is correct
27 Correct 194 ms 24040 KB Output is correct
28 Correct 189 ms 24092 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 268 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Incorrect 0 ms 288 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -