Submission #447608

# Submission time Handle Problem Language Result Execution time Memory
447608 2021-07-27T06:35:47 Z EliteCallsYou Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
243 ms 25876 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std ;

//////////////////////////////////////////////////
vector < int > mp[1001] ;
bool ans = true ;
////////////////////////////////////////////////

int construct(std::vector<std::vector<int>> p) {
	int n = (int)p.size();
	///////////////////////////////////////
	for ( int i = 0 ; i < n ; i ++ ){
		for ( int j = 0 ; j < n ; j ++ ){
			if ( p[i][j] && i != j ){
				mp[i].push_back(j) ;
				mp[j].push_back(i) ;
			}
		}
	}
	for ( int i = 0 ; i < n ; i ++ ){
		if ( (int)mp[i].size() == 2 ){
			return 0 ;
		}
	}
	//////////////////////////////////////
	bool been[1001] = {false} ;
	int bridge[n][n] ;
	for ( int i = 0 ; i < n ; i ++ ){
		for ( int j = 0 ; j < n ; j ++ ){
			bridge[i][j] = 0 ;
		}
	}


	for ( int i = 0 ; i < n ; i ++ ){
		for ( int j = i+1 ; j < n ; j ++ ){
			if ( p[i][j] ){ continue ; }
			for ( int child : mp[i] ){
				if ( p[child][j] ){
					return 0 ;
				}
			}
		}
	}


	for (int i = 0 ; i < n ; i++ ) {

		int last = -1 ;
		for ( int j = i+1 ; j < n ; j ++ ){

			if ( p[i][j] ){
				been[j] = true ;
				last = j ;
				for ( int l = j-1 ; l >= i ; l -- ){
					if ( p[i][l] ){
						bridge[l][j] = 1 ;
						bridge[j][l] = 1 ;
						break ;
					}
				}
			}
		}
		if ( last != -1 ){
			bridge[i][last] = 1 ;
			bridge[last][i] = 1 ;
		}
	}
	/////////////////////////////////////
	std::vector<std::vector<int>> answer;
	for ( int i = 0 ; i < n ; i ++ ){
		std::vector < int > row ;
		for ( int j = 0 ; j < n ; j ++ ){
			row.push_back(bridge[i][j]) ;
		}answer.push_back(row) ;
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:27:7: warning: variable 'been' set but not used [-Wunused-but-set-variable]
   27 |  bool been[1001] = {false} ;
      |       ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 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 Incorrect 0 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 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 10 ms 1356 KB Output is correct
9 Correct 243 ms 25876 KB Output is correct
10 Incorrect 1 ms 204 KB Too many ways to get from 0 to 4, should be 2 found no less than 3
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Too many ways to get from 1 to 4, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 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 Incorrect 0 ms 204 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -