답안 #88852

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
88852 2018-12-09T08:53:54 Z zviki Triumphal arch (POI13_luk) C++14
0 / 100
131 ms 132096 KB
#include <iostream>
#include <algorithm>
#include <stdio.h> 
#include <string.h>

#define 	avg(a, b) 	((a + b) / 2)
#define 	ARR_SIZE 	10000

using namespace std;

int map_of_cities[ARR_SIZE][ARR_SIZE];

int num_not_satisfy(bool visited_set[], int num_workers, int city)
{	
	int i, child_city, children = map_of_cities[city][0], rec_res = 0, num_children = 0;
	visited_set[city] = true;
	for (i = 1; i <= children; i++) {
		child_city = map_of_cities[city][i];
		if (visited_set[child_city] ==  false) {
			num_children++;
			rec_res += num_not_satisfy(visited_set, num_workers, child_city);
		}	
	}
	if (num_children + rec_res < num_workers) {
		return 0;
	} else {
		return children + rec_res - num_workers;
	}
}

int main() 
{
	int n, i, res, bsearch_start, bsearch_end, bsearch_mid, road_from, road_to; 	
	cin >> n;
	for (i = 0; i < ARR_SIZE; i++) { 
		memset(map_of_cities[i], 0, ARR_SIZE * sizeof(int));
	}
	for (i = 1; i < n; i++) {
		cin >> road_from >> road_to;
		map_of_cities[road_from][++(map_of_cities[road_from][0])] = road_to;
		map_of_cities[road_to][++(map_of_cities[road_to][0])] = road_from;
	}

	for (bsearch_start = 0, bsearch_end = n; bsearch_start < bsearch_end; ) {
		bsearch_mid = avg(bsearch_start, bsearch_end);
		bool visited_set[ARR_SIZE] = { false };
		res = num_not_satisfy(visited_set, bsearch_mid, 1);
		if (res != 0) {
			bsearch_start = bsearch_mid + 1;
		} else {
			bsearch_end = bsearch_mid;
		}
	}

	res = bsearch_start;
	cout << res << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 122 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 130 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 126 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 131 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 111 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 117 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 106 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 111 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 119 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 108 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -