답안 #447594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447594 2021-07-27T05:11:02 Z EliteCallsYou 슈퍼트리 잇기 (IOI20_supertrees) C++17
0 / 100
1 ms 204 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std ;

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

void DFS( int v, int cur ){
	if ( used[v] ){ return ; }
	used[v] = true ;
	bool found = false ;
	for ( int child : mp[v] ){
		if ( used[child] ){ continue ; }
		found = true ;
		DFS(child,cur+1) ;
	}
	if ( !found ){
		if ( cur < 3 ){ ans = false ; return ; }
	}
}
////////////////////////////////////////////////

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] ){
				mp[i].push_back(j) ;
				mp[j].push_back(i) ;
			}
		}
	}
	for ( int i = 0 ; i < n ; i ++ ){
		DFS(i,1) ;
		if ( !ans ){
			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++ ) {
		if ( been[i] ){ continue ; }

		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 ;
					}
				}
			}
			else{
				for ( int l = 0 ; l < j ; l ++ ){
					if ( p[i][l] && p[l][j] ){
						return 0;
					}
				}
			}
		}
		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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -