Submission #305535

# Submission time Handle Problem Language Result Execution time Memory
305535 2020-09-23T13:30:11 Z JustInCase Stations (IOI20_stations) C++17
100 / 100
1037 ms 1116 KB
#include "stations.h"
#include <vector>
#include <iostream>
#include <algorithm>

#define int32_t int
#define int64_t long long

const int32_t MAX_N = 1000;

struct Vertex {
	int32_t label;
	std::vector< int32_t > v;
};

Vertex g[MAX_N + 5];

void dfs(int32_t u, int32_t &t, int32_t par, int32_t dep) {
	if(dep % 2 == 0) {
		g[u].label = t++;
	}

	for(auto &v : g[u].v) {
		if(v != par) {
			dfs(v, t, u, dep + 1);
		}
	}

	if(dep % 2 != 0) {
		g[u].label = t++;
	}
}

std::vector< int32_t > label(int32_t n, int32_t k, std::vector< int32_t > u, std::vector< int32_t > v) {
	for(int32_t i = 0; i < n; i++) {
		g[i].v.clear();
	}

	for(int32_t i = 0; i < n - 1; i++) {
		g[u[i]].v.push_back(v[i]);
		g[v[i]].v.push_back(u[i]);
	}
	
	int32_t t = 0;
	dfs(0, t, -1, 0);
	
	std::vector< int32_t > labels(n);
	for(int32_t i = 0; i < n; i++) {
		labels[i] = g[i].label;
	}

	return labels;
}

int32_t find_next_station(int32_t s, int32_t t, std::vector< int32_t > c) {
	if(s < c[0]) {
		if(t > c[c.size() - 2]) {
			return c[c.size() - 1];
		}
		if(t < s) {
			return c[c.size() - 1];
		}
		else {
			return *std::lower_bound(c.begin(), c.end(), t);
		}
	}
	else {
		if(t <= c[0]) {
			return c[0];
		}
		else if(t > s) {
			return c[0];
		}
		else {
			return *--std::upper_bound(c.begin(), c.end(), t);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 551 ms 1024 KB Output is correct
2 Correct 479 ms 1008 KB Output is correct
3 Correct 892 ms 768 KB Output is correct
4 Correct 647 ms 872 KB Output is correct
5 Correct 635 ms 1024 KB Output is correct
6 Correct 479 ms 1024 KB Output is correct
7 Correct 463 ms 768 KB Output is correct
8 Correct 4 ms 876 KB Output is correct
9 Correct 6 ms 868 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 491 ms 812 KB Output is correct
2 Correct 671 ms 820 KB Output is correct
3 Correct 1037 ms 768 KB Output is correct
4 Correct 843 ms 868 KB Output is correct
5 Correct 712 ms 880 KB Output is correct
6 Correct 547 ms 824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 554 ms 1024 KB Output is correct
2 Correct 469 ms 1064 KB Output is correct
3 Correct 933 ms 1008 KB Output is correct
4 Correct 679 ms 872 KB Output is correct
5 Correct 629 ms 864 KB Output is correct
6 Correct 470 ms 1024 KB Output is correct
7 Correct 456 ms 1024 KB Output is correct
8 Correct 2 ms 892 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 2 ms 876 KB Output is correct
11 Correct 588 ms 864 KB Output is correct
12 Correct 480 ms 1024 KB Output is correct
13 Correct 478 ms 1116 KB Output is correct
14 Correct 463 ms 820 KB Output is correct
15 Correct 58 ms 768 KB Output is correct
16 Correct 80 ms 840 KB Output is correct
17 Correct 106 ms 932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 930 ms 1008 KB Output is correct
2 Correct 710 ms 1040 KB Output is correct
3 Correct 614 ms 1024 KB Output is correct
4 Correct 3 ms 868 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 2 ms 992 KB Output is correct
7 Correct 621 ms 872 KB Output is correct
8 Correct 972 ms 868 KB Output is correct
9 Correct 742 ms 768 KB Output is correct
10 Correct 588 ms 872 KB Output is correct
11 Correct 6 ms 768 KB Output is correct
12 Correct 7 ms 1024 KB Output is correct
13 Correct 5 ms 1008 KB Output is correct
14 Correct 4 ms 868 KB Output is correct
15 Correct 2 ms 880 KB Output is correct
16 Correct 549 ms 768 KB Output is correct
17 Correct 524 ms 872 KB Output is correct
18 Correct 525 ms 768 KB Output is correct
19 Correct 505 ms 872 KB Output is correct
20 Correct 522 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 539 ms 1024 KB Output is correct
2 Correct 490 ms 1008 KB Output is correct
3 Correct 903 ms 868 KB Output is correct
4 Correct 669 ms 768 KB Output is correct
5 Correct 623 ms 992 KB Output is correct
6 Correct 535 ms 1024 KB Output is correct
7 Correct 496 ms 800 KB Output is correct
8 Correct 3 ms 880 KB Output is correct
9 Correct 4 ms 864 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 467 ms 768 KB Output is correct
12 Correct 628 ms 768 KB Output is correct
13 Correct 942 ms 768 KB Output is correct
14 Correct 766 ms 776 KB Output is correct
15 Correct 697 ms 768 KB Output is correct
16 Correct 452 ms 784 KB Output is correct
17 Correct 628 ms 768 KB Output is correct
18 Correct 508 ms 1024 KB Output is correct
19 Correct 523 ms 1008 KB Output is correct
20 Correct 548 ms 800 KB Output is correct
21 Correct 62 ms 768 KB Output is correct
22 Correct 91 ms 768 KB Output is correct
23 Correct 100 ms 812 KB Output is correct
24 Correct 6 ms 868 KB Output is correct
25 Correct 6 ms 768 KB Output is correct
26 Correct 5 ms 860 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 2 ms 768 KB Output is correct
29 Correct 567 ms 768 KB Output is correct
30 Correct 528 ms 768 KB Output is correct
31 Correct 575 ms 1024 KB Output is correct
32 Correct 677 ms 768 KB Output is correct
33 Correct 803 ms 872 KB Output is correct
34 Correct 396 ms 1024 KB Output is correct
35 Correct 471 ms 1100 KB Output is correct
36 Correct 542 ms 1024 KB Output is correct
37 Correct 503 ms 888 KB Output is correct
38 Correct 609 ms 1020 KB Output is correct
39 Correct 457 ms 1024 KB Output is correct
40 Correct 475 ms 1016 KB Output is correct
41 Correct 520 ms 900 KB Output is correct
42 Correct 71 ms 844 KB Output is correct
43 Correct 141 ms 940 KB Output is correct
44 Correct 158 ms 768 KB Output is correct
45 Correct 164 ms 796 KB Output is correct
46 Correct 346 ms 812 KB Output is correct
47 Correct 355 ms 780 KB Output is correct
48 Correct 69 ms 896 KB Output is correct
49 Correct 79 ms 1024 KB Output is correct