Submission #406572

# Submission time Handle Problem Language Result Execution time Memory
406572 2021-05-17T18:15:41 Z priority_queue Stations (IOI20_stations) C++14
100 / 100
1140 ms 748 KB
#include <bits/stdc++.h>

#define forint(i, N) for (int i = 0; i < (N); i++)

using namespace std;

vector<int> value;
vector<bool> visited;

int minval = 0;

void go(vector< vector<int> >& graph, int n, bool odd) {

	visited[n] = true;

	if (odd) {
		for (auto& i : graph[n]) {
			if (!visited[i]) {
				go(graph, i, !odd);
			}
		}
		value[n] = minval;
		minval++;
	}
	else {
		value[n] = minval;
		minval++;
		for (auto& i : graph[n]) {
			if (!visited[i]) {
				go(graph, i, !odd);
			}
		}
	}
	
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector< vector<int> > graph(n);

	visited.clear();
	visited.resize(n);
	fill(visited.begin(), visited.end(), false);

	value.clear();
	value.resize(n);
	fill(value.begin(), value.end(), -1);

	forint(i, n - 1) {
		graph[u[i]].push_back(v[i]);
		graph[v[i]].push_back(u[i]);
	}

	minval = 0;
	go(graph, 0, true);

	return value;
}

int find_next_station(int s, int t, vector<int> c) {

	if (s < c[0]) {
		if (t < s || t > c[c.size() - 1]) {
			return c[c.size() - 1];
		}
		forint(i, c.size()) {
			if (c[i] >= t) {
				return c[i];
			}
		}
	}
	else {
		if (t > s || t < c[0]) {
			return c[0];
		}
		for (int i = c.size() - 1; i >= 0; i--) {
			if (t >= c[i]) {
				return c[i];
			}
		}
	}
	
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:3:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define forint(i, N) for (int i = 0; i < (N); i++)
      |                                        ^
stations.cpp:65:3: note: in expansion of macro 'forint'
   65 |   forint(i, c.size()) {
      |   ^~~~~~
stations.cpp:82:1: warning: control reaches end of non-void function [-Wreturn-type]
   82 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 655 ms 520 KB Output is correct
2 Correct 475 ms 520 KB Output is correct
3 Correct 1095 ms 400 KB Output is correct
4 Correct 883 ms 476 KB Output is correct
5 Correct 694 ms 492 KB Output is correct
6 Correct 523 ms 488 KB Output is correct
7 Correct 606 ms 484 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 6 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 651 ms 528 KB Output is correct
2 Correct 640 ms 512 KB Output is correct
3 Correct 1140 ms 468 KB Output is correct
4 Correct 804 ms 400 KB Output is correct
5 Correct 657 ms 488 KB Output is correct
6 Correct 555 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 586 ms 520 KB Output is correct
2 Correct 464 ms 488 KB Output is correct
3 Correct 1063 ms 512 KB Output is correct
4 Correct 761 ms 528 KB Output is correct
5 Correct 738 ms 492 KB Output is correct
6 Correct 529 ms 600 KB Output is correct
7 Correct 526 ms 600 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 5 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 754 ms 484 KB Output is correct
12 Correct 639 ms 628 KB Output is correct
13 Correct 535 ms 748 KB Output is correct
14 Correct 529 ms 484 KB Output is correct
15 Correct 54 ms 448 KB Output is correct
16 Correct 65 ms 528 KB Output is correct
17 Correct 113 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 898 ms 400 KB Output is correct
2 Correct 792 ms 484 KB Output is correct
3 Correct 650 ms 488 KB Output is correct
4 Correct 3 ms 472 KB Output is correct
5 Correct 5 ms 468 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 629 ms 400 KB Output is correct
8 Correct 1051 ms 400 KB Output is correct
9 Correct 825 ms 480 KB Output is correct
10 Correct 655 ms 464 KB Output is correct
11 Correct 6 ms 468 KB Output is correct
12 Correct 7 ms 480 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 476 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 554 ms 400 KB Output is correct
17 Correct 707 ms 400 KB Output is correct
18 Correct 644 ms 480 KB Output is correct
19 Correct 652 ms 400 KB Output is correct
20 Correct 641 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 678 ms 624 KB Output is correct
2 Correct 621 ms 520 KB Output is correct
3 Correct 1113 ms 524 KB Output is correct
4 Correct 866 ms 400 KB Output is correct
5 Correct 818 ms 484 KB Output is correct
6 Correct 489 ms 612 KB Output is correct
7 Correct 463 ms 532 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 6 ms 468 KB Output is correct
10 Correct 2 ms 464 KB Output is correct
11 Correct 539 ms 484 KB Output is correct
12 Correct 680 ms 528 KB Output is correct
13 Correct 999 ms 400 KB Output is correct
14 Correct 783 ms 488 KB Output is correct
15 Correct 758 ms 488 KB Output is correct
16 Correct 596 ms 528 KB Output is correct
17 Correct 633 ms 400 KB Output is correct
18 Correct 546 ms 612 KB Output is correct
19 Correct 530 ms 596 KB Output is correct
20 Correct 504 ms 656 KB Output is correct
21 Correct 73 ms 444 KB Output is correct
22 Correct 81 ms 548 KB Output is correct
23 Correct 102 ms 656 KB Output is correct
24 Correct 6 ms 480 KB Output is correct
25 Correct 7 ms 476 KB Output is correct
26 Correct 5 ms 468 KB Output is correct
27 Correct 5 ms 468 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 539 ms 488 KB Output is correct
30 Correct 559 ms 488 KB Output is correct
31 Correct 577 ms 400 KB Output is correct
32 Correct 603 ms 588 KB Output is correct
33 Correct 623 ms 488 KB Output is correct
34 Correct 367 ms 528 KB Output is correct
35 Correct 490 ms 688 KB Output is correct
36 Correct 531 ms 648 KB Output is correct
37 Correct 524 ms 744 KB Output is correct
38 Correct 610 ms 656 KB Output is correct
39 Correct 446 ms 732 KB Output is correct
40 Correct 545 ms 624 KB Output is correct
41 Correct 489 ms 604 KB Output is correct
42 Correct 72 ms 556 KB Output is correct
43 Correct 152 ms 532 KB Output is correct
44 Correct 173 ms 528 KB Output is correct
45 Correct 197 ms 528 KB Output is correct
46 Correct 387 ms 600 KB Output is correct
47 Correct 359 ms 656 KB Output is correct
48 Correct 76 ms 528 KB Output is correct
49 Correct 69 ms 596 KB Output is correct