답안 #304943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304943 2020-09-22T09:01:16 Z galca 기지국 (IOI20_stations) C++14
0 / 100
1047 ms 1024 KB
#include "stations.h"
#include <vector>

using namespace std;

int label_nodes(vector<vector<int>>& nodes, vector<int>& labels, bool isMin, int id, int me, int father) {
	if ((father != -1) && (nodes[me].size() == 1)) {
		// a leaf
		labels[me] = id;
		return id+1;
	}
	if (isMin) {
		labels[me] = id;
		int next_id = id + 1;
		for (int i = 0; i < nodes[me].size(); i++) {		
			if (nodes[me][i] != father) {
				next_id = label_nodes(nodes, labels, !isMin, next_id, nodes[me][i], me);
			}
		}
		return next_id;
	}
	else {
		int next_id = id + 1;
		for (int i = 0; i < nodes[me].size(); i++) {
			if (nodes[me][i] != father) {
				next_id = label_nodes(nodes, labels, !isMin, next_id, nodes[me][i], me);
			}
		}
		labels[me] = next_id;
		return next_id + 1;
	}
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	vector<vector<int>> nodes(n);
	vector<int> labels(n);

	for (int i = 0; i < n; i++) {
		vector<int> edges;
		nodes.push_back(edges);
	}
	for (int i = 0; i < u.size(); i++) {
		nodes[u[i]].push_back(v[i]);
		nodes[v[i]].push_back(u[i]);
	}
	int root = 0;
	labels[0] = 0;

	label_nodes(nodes, labels, true, 0, 0, -1);

	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	bool isMin = c[0] > s;
	if (isMin) {
		int father = c[c.size()-1];
		if (t < s) {
			return father;
		}
		for (int i = 0; i < c.size(); i++) {
			if (t < c[i])
				return c[i];
		}
		return father;
	}
	else {
		int father = c[0];
		if (t > s) {
			return father;
		}
		if (t < c[0]) {
			return father;
		}
		for (int i = 1; i < c.size(); i++) {
			if (t < c[i])
				return c[i - 1];
		}
		return c[c.size()-1];
	}
	return c[0];
}

Compilation message

stations.cpp: In function 'int label_nodes(std::vector<std::vector<int> >&, std::vector<int>&, bool, int, int, int)':
stations.cpp:15:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |   for (int i = 0; i < nodes[me].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~
stations.cpp:24:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for (int i = 0; i < nodes[me].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for (int i = 0; i < u.size(); i++) {
      |                  ~~^~~~~~~~~~
stations.cpp:46:6: warning: unused variable 'root' [-Wunused-variable]
   46 |  int root = 0;
      |      ^~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for (int i = 0; i < c.size(); i++) {
      |                   ~~^~~~~~~~~~
stations.cpp:75:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |   for (int i = 1; i < c.size(); i++) {
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 484 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1493
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 348 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=2, label=1165
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 587 ms 960 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1047 ms 768 KB Output is correct
2 Incorrect 930 ms 640 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 620 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -