Submission #304955

# Submission time Handle Problem Language Result Execution time Memory
304955 2020-09-22T09:20:21 Z galca Stations (IOI20_stations) C++14
0 / 100
1099 ms 1036 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;
		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 < u.size(); i++) {
		nodes[u[i]].push_back(v[i]);
		nodes[v[i]].push_back(u[i]);
	}

	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:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for (int i = 0; i < u.size(); i++) {
      |                  ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:55:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for (int i = 0; i < c.size(); i++) {
      |                   ~~^~~~~~~~~~
stations.cpp:69:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   for (int i = 1; i < c.size(); i++) {
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 778 ms 1036 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 534 ms 768 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 798 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1099 ms 640 KB Output is correct
2 Incorrect 771 ms 780 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 746 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -