Submission #304965

# Submission time Handle Problem Language Result Execution time Memory
304965 2020-09-22T09:48:55 Z galca Stations (IOI20_stations) C++14
100 / 100
1253 ms 1056 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];
		// i am min. lower ids are not in my subtree
		if (t < s) {
			return father;
		}
		for (int i = 0; i < c.size(); i++) {
			if (t <= c[i])
				return c[i];
		}
		return father;
	}
	else {
		// i am max. my father and children are lower
		int father = c[0];
		// larger ids are through father
		if (t > s) {
			return father;
		}
		// smaller than my first son are there, too
		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:56:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for (int i = 0; i < c.size(); i++) {
      |                   ~~^~~~~~~~~~
stations.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for (int i = 1; i < c.size(); i++) {
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 662 ms 1016 KB Output is correct
2 Correct 576 ms 984 KB Output is correct
3 Correct 935 ms 640 KB Output is correct
4 Correct 767 ms 640 KB Output is correct
5 Correct 581 ms 640 KB Output is correct
6 Correct 526 ms 768 KB Output is correct
7 Correct 533 ms 896 KB Output is correct
8 Correct 3 ms 928 KB Output is correct
9 Correct 3 ms 776 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 490 ms 840 KB Output is correct
2 Correct 577 ms 768 KB Output is correct
3 Correct 1146 ms 640 KB Output is correct
4 Correct 849 ms 640 KB Output is correct
5 Correct 799 ms 664 KB Output is correct
6 Correct 524 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 656 ms 1028 KB Output is correct
2 Correct 531 ms 1032 KB Output is correct
3 Correct 975 ms 760 KB Output is correct
4 Correct 854 ms 732 KB Output is correct
5 Correct 660 ms 640 KB Output is correct
6 Correct 474 ms 768 KB Output is correct
7 Correct 576 ms 1012 KB Output is correct
8 Correct 2 ms 660 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 0 ms 640 KB Output is correct
11 Correct 685 ms 768 KB Output is correct
12 Correct 577 ms 1024 KB Output is correct
13 Correct 527 ms 1056 KB Output is correct
14 Correct 541 ms 800 KB Output is correct
15 Correct 55 ms 688 KB Output is correct
16 Correct 68 ms 816 KB Output is correct
17 Correct 138 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1095 ms 904 KB Output is correct
2 Correct 753 ms 640 KB Output is correct
3 Correct 679 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 4 ms 640 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 698 ms 672 KB Output is correct
8 Correct 1253 ms 800 KB Output is correct
9 Correct 738 ms 904 KB Output is correct
10 Correct 684 ms 640 KB Output is correct
11 Correct 7 ms 672 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 4 ms 780 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 567 ms 876 KB Output is correct
17 Correct 615 ms 640 KB Output is correct
18 Correct 618 ms 640 KB Output is correct
19 Correct 551 ms 940 KB Output is correct
20 Correct 663 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 593 ms 1024 KB Output is correct
2 Correct 589 ms 760 KB Output is correct
3 Correct 974 ms 904 KB Output is correct
4 Correct 799 ms 768 KB Output is correct
5 Correct 709 ms 640 KB Output is correct
6 Correct 484 ms 1008 KB Output is correct
7 Correct 543 ms 760 KB Output is correct
8 Correct 3 ms 800 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 0 ms 640 KB Output is correct
11 Correct 641 ms 760 KB Output is correct
12 Correct 607 ms 768 KB Output is correct
13 Correct 1228 ms 776 KB Output is correct
14 Correct 850 ms 736 KB Output is correct
15 Correct 689 ms 768 KB Output is correct
16 Correct 707 ms 780 KB Output is correct
17 Correct 839 ms 652 KB Output is correct
18 Correct 457 ms 1024 KB Output is correct
19 Correct 533 ms 1024 KB Output is correct
20 Correct 528 ms 896 KB Output is correct
21 Correct 70 ms 640 KB Output is correct
22 Correct 92 ms 768 KB Output is correct
23 Correct 154 ms 904 KB Output is correct
24 Correct 8 ms 768 KB Output is correct
25 Correct 8 ms 768 KB Output is correct
26 Correct 5 ms 928 KB Output is correct
27 Correct 4 ms 652 KB Output is correct
28 Correct 1 ms 768 KB Output is correct
29 Correct 630 ms 904 KB Output is correct
30 Correct 729 ms 640 KB Output is correct
31 Correct 608 ms 640 KB Output is correct
32 Correct 571 ms 736 KB Output is correct
33 Correct 643 ms 640 KB Output is correct
34 Correct 477 ms 768 KB Output is correct
35 Correct 512 ms 1024 KB Output is correct
36 Correct 509 ms 1032 KB Output is correct
37 Correct 531 ms 776 KB Output is correct
38 Correct 491 ms 1008 KB Output is correct
39 Correct 598 ms 976 KB Output is correct
40 Correct 507 ms 740 KB Output is correct
41 Correct 572 ms 904 KB Output is correct
42 Correct 69 ms 768 KB Output is correct
43 Correct 115 ms 812 KB Output is correct
44 Correct 128 ms 800 KB Output is correct
45 Correct 198 ms 904 KB Output is correct
46 Correct 428 ms 768 KB Output is correct
47 Correct 352 ms 768 KB Output is correct
48 Correct 79 ms 812 KB Output is correct
49 Correct 71 ms 768 KB Output is correct