Submission #519125

# Submission time Handle Problem Language Result Execution time Memory
519125 2022-01-25T17:20:42 Z LucaIlie Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
194 ms 24300 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][0]];
            for ( i = 0; i < f[x].size(); i++ ) {
                for ( j = 0; 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;
            for ( i = 1; i < a; i++ ) {
                b[f[x][0]][f[x][i]] = 1;
                b[f[x][i]][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:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |                 for ( j = 0; 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 292 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 284 KB Output is correct
6 Correct 11 ms 1276 KB Output is correct
7 Correct 186 ms 24044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 284 KB Output is correct
6 Correct 11 ms 1276 KB Output is correct
7 Correct 186 ms 24044 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 7 ms 1220 KB Output is correct
13 Correct 168 ms 24096 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 796 KB Output is correct
17 Correct 89 ms 14188 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 272 KB Output is correct
20 Correct 43 ms 6296 KB Output is correct
21 Correct 178 ms 24300 KB Output is correct
22 Correct 172 ms 24184 KB Output is correct
23 Correct 178 ms 24088 KB Output is correct
24 Correct 184 ms 24116 KB Output is correct
25 Correct 73 ms 14200 KB Output is correct
26 Correct 76 ms 14276 KB Output is correct
27 Correct 194 ms 24040 KB Output is correct
28 Correct 183 ms 24152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 0 ms 204 KB Answer gives possible 0 while actual possible 1
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 288 KB Output is correct
2 Incorrect 1 ms 204 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 284 KB Output is correct
6 Correct 11 ms 1276 KB Output is correct
7 Correct 186 ms 24044 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 7 ms 1220 KB Output is correct
13 Correct 168 ms 24096 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 796 KB Output is correct
17 Correct 89 ms 14188 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 272 KB Output is correct
20 Correct 43 ms 6296 KB Output is correct
21 Correct 178 ms 24300 KB Output is correct
22 Correct 172 ms 24184 KB Output is correct
23 Correct 178 ms 24088 KB Output is correct
24 Correct 184 ms 24116 KB Output is correct
25 Correct 73 ms 14200 KB Output is correct
26 Correct 76 ms 14276 KB Output is correct
27 Correct 194 ms 24040 KB Output is correct
28 Correct 183 ms 24152 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 296 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Incorrect 0 ms 204 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 284 KB Output is correct
6 Correct 11 ms 1276 KB Output is correct
7 Correct 186 ms 24044 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 7 ms 1220 KB Output is correct
13 Correct 168 ms 24096 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 796 KB Output is correct
17 Correct 89 ms 14188 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 272 KB Output is correct
20 Correct 43 ms 6296 KB Output is correct
21 Correct 178 ms 24300 KB Output is correct
22 Correct 172 ms 24184 KB Output is correct
23 Correct 178 ms 24088 KB Output is correct
24 Correct 184 ms 24116 KB Output is correct
25 Correct 73 ms 14200 KB Output is correct
26 Correct 76 ms 14276 KB Output is correct
27 Correct 194 ms 24040 KB Output is correct
28 Correct 183 ms 24152 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 296 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Incorrect 0 ms 204 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -