Submission #88855

# Submission time Handle Problem Language Result Execution time Memory
88855 2018-12-09T11:23:13 Z 123456 Triumphal arch (POI13_luk) C++14
0 / 100
462 ms 132096 KB
#include <iostream>
#include <vector>
#include <map>

using namespace std;


vector<vector<int>> graph;
vector<bool> visited;


int check(int currentCity, int k) {
	int childrenSum = 0;

	visited[currentCity] = true;
	
	for (int i = 0; i < graph[currentCity].size(); i++) {
		if (!visited[i]) {
			childrenSum += check(graph[currentCity][i], k);
		}
	}
	int numberOfChildren = graph[currentCity].size() - 1;
	if (currentCity == 0) numberOfChildren++;
	return max(0, numberOfChildren + childrenSum - k);
}

int main() {
	int numberOfTowns;
	cin >> numberOfTowns;
	visited.resize(numberOfTowns);
	graph.resize(numberOfTowns);
	for (int i = 0; i < numberOfTowns - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;

		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	int start = 1;
	int end = numberOfTowns;

	int currentK = 0;
	while (start != end) {
		visited.resize(numberOfTowns, false);
		currentK = (start + end) / 2;
		if (!check(0, currentK)) {
			end = currentK;
		}
		else {
			start = currentK + 1;
		}
	}
	cout << currentK << endl;

	return 0;
}

Compilation message

luk.cpp: In function 'int check(int, int)':
luk.cpp:17:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < graph[currentCity].size(); i++) {
                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 150 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 132096 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 149 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 30 ms 132096 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 228 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 332 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 462 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 461 ms 132096 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -