Submission #436420

# Submission time Handle Problem Language Result Execution time Memory
436420 2021-06-24T13:29:44 Z frodakcin Stations (IOI20_stations) C++17
100 / 100
1265 ms 776 KB
#include "stations.h"
#include <algorithm>
#include <vector>
#include <functional>

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n, -1);
	std::vector<std::vector<int> > a(n, std::vector<int>());
	for(int i=0;i<n-1;++i)
		a[u[i]].push_back(v[i]), a[v[i]].push_back(u[i]);

	int ctr=0;
	std::function<void(int,int,bool)> dfs=[&](int n, int p, bool t)
	{
		if(t) labels[n]=ctr++;
		for(int x:a[n])
			if(x!=p)
				dfs(x, n, !t);
		if(!t) labels[n]=ctr++;
	};
	dfs(0, -1, 0);
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if(s < c[0]) // all neighbors postorder
	{
		if(t<s) return c.back();
		if(t>c.back()) return c.back();
		return *std::lower_bound(c.begin(), c.end(), t);
	}
	else // all neighbors preorder
	{
		if(t>s) return c[0];
		if(t<c[0]) return c[0];
		return *std::prev(std::upper_bound(c.begin(), c.end(), t));
	}
}
# Verdict Execution time Memory Grader output
1 Correct 874 ms 636 KB Output is correct
2 Correct 548 ms 600 KB Output is correct
3 Correct 1265 ms 472 KB Output is correct
4 Correct 822 ms 600 KB Output is correct
5 Correct 679 ms 400 KB Output is correct
6 Correct 542 ms 636 KB Output is correct
7 Correct 519 ms 620 KB Output is correct
8 Correct 3 ms 584 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 665 ms 548 KB Output is correct
2 Correct 697 ms 544 KB Output is correct
3 Correct 1001 ms 452 KB Output is correct
4 Correct 809 ms 472 KB Output is correct
5 Correct 920 ms 632 KB Output is correct
6 Correct 661 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 647 ms 716 KB Output is correct
2 Correct 548 ms 600 KB Output is correct
3 Correct 1067 ms 620 KB Output is correct
4 Correct 836 ms 472 KB Output is correct
5 Correct 775 ms 476 KB Output is correct
6 Correct 481 ms 528 KB Output is correct
7 Correct 560 ms 660 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 7 ms 468 KB Output is correct
10 Correct 2 ms 464 KB Output is correct
11 Correct 758 ms 476 KB Output is correct
12 Correct 671 ms 776 KB Output is correct
13 Correct 604 ms 712 KB Output is correct
14 Correct 627 ms 472 KB Output is correct
15 Correct 66 ms 472 KB Output is correct
16 Correct 97 ms 492 KB Output is correct
17 Correct 159 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 977 ms 400 KB Output is correct
2 Correct 935 ms 480 KB Output is correct
3 Correct 775 ms 472 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 4 ms 464 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 698 ms 584 KB Output is correct
8 Correct 957 ms 400 KB Output is correct
9 Correct 771 ms 400 KB Output is correct
10 Correct 767 ms 400 KB Output is correct
11 Correct 4 ms 472 KB Output is correct
12 Correct 6 ms 520 KB Output is correct
13 Correct 7 ms 468 KB Output is correct
14 Correct 6 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 506 ms 480 KB Output is correct
17 Correct 596 ms 476 KB Output is correct
18 Correct 733 ms 400 KB Output is correct
19 Correct 717 ms 496 KB Output is correct
20 Correct 710 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 727 ms 596 KB Output is correct
2 Correct 659 ms 740 KB Output is correct
3 Correct 1162 ms 468 KB Output is correct
4 Correct 872 ms 476 KB Output is correct
5 Correct 892 ms 400 KB Output is correct
6 Correct 643 ms 604 KB Output is correct
7 Correct 537 ms 528 KB Output is correct
8 Correct 5 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 441 ms 552 KB Output is correct
12 Correct 602 ms 528 KB Output is correct
13 Correct 914 ms 468 KB Output is correct
14 Correct 1144 ms 400 KB Output is correct
15 Correct 688 ms 400 KB Output is correct
16 Correct 630 ms 472 KB Output is correct
17 Correct 857 ms 520 KB Output is correct
18 Correct 625 ms 720 KB Output is correct
19 Correct 506 ms 664 KB Output is correct
20 Correct 548 ms 472 KB Output is correct
21 Correct 83 ms 420 KB Output is correct
22 Correct 92 ms 404 KB Output is correct
23 Correct 110 ms 528 KB Output is correct
24 Correct 6 ms 468 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 4 ms 464 KB Output is correct
27 Correct 5 ms 472 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 731 ms 400 KB Output is correct
30 Correct 756 ms 476 KB Output is correct
31 Correct 720 ms 400 KB Output is correct
32 Correct 747 ms 400 KB Output is correct
33 Correct 584 ms 472 KB Output is correct
34 Correct 410 ms 528 KB Output is correct
35 Correct 617 ms 632 KB Output is correct
36 Correct 584 ms 596 KB Output is correct
37 Correct 450 ms 664 KB Output is correct
38 Correct 545 ms 532 KB Output is correct
39 Correct 453 ms 548 KB Output is correct
40 Correct 598 ms 728 KB Output is correct
41 Correct 609 ms 556 KB Output is correct
42 Correct 87 ms 528 KB Output is correct
43 Correct 145 ms 528 KB Output is correct
44 Correct 140 ms 544 KB Output is correct
45 Correct 204 ms 556 KB Output is correct
46 Correct 474 ms 528 KB Output is correct
47 Correct 377 ms 528 KB Output is correct
48 Correct 57 ms 624 KB Output is correct
49 Correct 52 ms 528 KB Output is correct