제출 #519592

#제출 시각아이디문제언어결과실행 시간메모리
519592LucaIlieConnecting Supertrees (IOI20_supertrees)C++17
21 / 100
202 ms22240 KiB
#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, first, last, sef1, sef2; 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] == 1 ) 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 ); } for ( x = 0; x < n; x++ ) { if ( f1[x].size() > 1 ) { int e2; e2 = 0; 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; if ( p[f1[x][i]][f1[x][j]] == 2 ) e2 = 1; } } if ( e2 ) { sef1 = sef2 = -1; for ( i = 0; i < f1[x].size(); i++ ) { if ( forest2.find( f1[x][i] ) != f1[x][i] && forest2.find( f1[x][i] ) != sef1 && forest2.find( f1[x][i] ) != sef2 ) { if ( sef1 == -1 ) sef1 = forest2.find( f1[x][i] ); else if ( sef2 == -1 ) sef2 = forest2.find( f1[x][i] ); else return 0; } } first = -1; last = -1; for ( i = 0; i < f1[x].size(); i++ ) { if ( forest2.find( f1[x][i] ) != f1[x][i] ) { b[f1[x][i]][forest2.find( f1[x][i] )] = 1; b[forest2.find( f1[x][i] )][f1[x][i]] = 1; } else { if ( last != -1 ) { b[last][f1[x][i]] = 1; b[f1[x][i]][last] = 1; } if ( first == -1 ) first = f1[x][i]; last = f1[x][i]; } } if ( first != last ) { b[first][last] = 1; b[last][first] = 1; } else return 0; for ( i = 0; i < f1[x].size(); i++ ) { for ( j = i + 1; j < f1[x].size(); j++ ) { if ( forest2.find( f1[x][i] ) == forest2.find( f1[x][j] ) ) { if ( p[f1[x][i]][f1[x][j]] != 1 ) return 0; } else { if ( p[f1[x][i]][f1[x][j]] != 2 ) return 0; } } } } else { 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; } } } } build( b ); return 1; }

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:69:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             for ( i = 0; i < f1[x].size(); i++ ) {
      |                          ~~^~~~~~~~~~~~~~
supertrees.cpp:70:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |                 for ( j = i + 1; j < f1[x].size(); j++ ) {
      |                                  ~~^~~~~~~~~~~~~~
supertrees.cpp:79:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |                 for ( i = 0; i < f1[x].size(); i++ ) {
      |                              ~~^~~~~~~~~~~~~~
supertrees.cpp:91:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |                 for ( i = 0; i < f1[x].size(); i++ ) {
      |                              ~~^~~~~~~~~~~~~~
supertrees.cpp:110:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |                 for ( i = 0; i < f1[x].size(); i++ ) {
      |                              ~~^~~~~~~~~~~~~~
supertrees.cpp:111:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |                     for ( j = i + 1; j < f1[x].size(); j++ ) {
      |                                      ~~^~~~~~~~~~~~~~
supertrees.cpp:122:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |                 for ( i = 0; i < f1[x].size() - 1; i++ ) {
      |                              ~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...