답안 #305155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
305155 2020-09-22T16:08:11 Z Temmie 기지국 (IOI20_stations) C++17
100 / 100
1194 ms 1056 KB
#include <bits/stdc++.h>

struct Node {
	std::vector <int> nei;
	int d, a, b;
	Node() : d(0), a(0), b(0) { }
};

struct Triplet {
	int x, y, z;
	Triplet(int X = 0, int Y = 0, int Z = 0) : x(X), y(Y), z(Z) { }
	bool operator<(const Triplet& other) const {
		if (x == other.x) return y > other.y;
		return x < other.x;
	}
};

int cnt;
void dfs(std::vector <Node>& g, int node = 0, int par = -1) {
	g[node].a = cnt++;
	g[node].d = par == -1 ? 0 : g[par].d + 1;
	for (int x : g[node].nei) if (x != par) dfs(g, x, node);
	g[node].b = cnt - 1;
}

std::vector <int> label(int n, int k, std::vector <int> u, std::vector <int> v) {
	
	cnt = 0;
	std::vector <int> r(n);
	std::vector <Node> g(n);
	for (int i = 0; i < n - 1; i++) {
		g[u[i]].nei.push_back(v[i]);
		g[v[i]].nei.push_back(u[i]);
	}
	dfs(g);
	std::vector <Triplet> tr(n);
	for (int i = 0; i < n; i++) tr[i] = Triplet(g[i].d & 1 ? g[i].b : g[i].a, g[i].d, i);
	std::sort(tr.begin(), tr.end());
	for (int i = 0; i < n; i++) r[tr[i].z] = i;
	return r;
	
}

int find_next_station(int s, int t, std::vector <int> c) {
	if (!(c.size() - 1)) return c.front();
	if (!s) for (int x : c) if (t <= x) return x;
	if (s < c.front()) {
		if (!(s <= t && t <= c[c.size() - 2])) return c.back();
		for (int x : c) if (t <= x) return x;
	}
	if (!(t <= s && c[1] <= t)) return c.front();
	for (int i = (int)c.size() - 1; i >= 0; i--) if (c[i] <= t) return c[i];
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 731 ms 1016 KB Output is correct
2 Correct 621 ms 1024 KB Output is correct
3 Correct 892 ms 640 KB Output is correct
4 Correct 829 ms 752 KB Output is correct
5 Correct 824 ms 672 KB Output is correct
6 Correct 499 ms 1008 KB Output is correct
7 Correct 681 ms 1008 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 2 ms 776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 533 ms 768 KB Output is correct
2 Correct 576 ms 776 KB Output is correct
3 Correct 1009 ms 640 KB Output is correct
4 Correct 1000 ms 752 KB Output is correct
5 Correct 668 ms 768 KB Output is correct
6 Correct 573 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 631 ms 1056 KB Output is correct
2 Correct 586 ms 1008 KB Output is correct
3 Correct 1004 ms 884 KB Output is correct
4 Correct 742 ms 800 KB Output is correct
5 Correct 562 ms 752 KB Output is correct
6 Correct 464 ms 872 KB Output is correct
7 Correct 462 ms 1024 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 559 ms 768 KB Output is correct
12 Correct 542 ms 1024 KB Output is correct
13 Correct 673 ms 1048 KB Output is correct
14 Correct 581 ms 768 KB Output is correct
15 Correct 90 ms 896 KB Output is correct
16 Correct 85 ms 768 KB Output is correct
17 Correct 122 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 913 ms 640 KB Output is correct
2 Correct 851 ms 644 KB Output is correct
3 Correct 527 ms 640 KB Output is correct
4 Correct 3 ms 752 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 685 ms 904 KB Output is correct
8 Correct 946 ms 776 KB Output is correct
9 Correct 881 ms 904 KB Output is correct
10 Correct 604 ms 904 KB Output is correct
11 Correct 5 ms 832 KB Output is correct
12 Correct 9 ms 768 KB Output is correct
13 Correct 6 ms 776 KB Output is correct
14 Correct 4 ms 776 KB Output is correct
15 Correct 2 ms 768 KB Output is correct
16 Correct 645 ms 640 KB Output is correct
17 Correct 594 ms 652 KB Output is correct
18 Correct 548 ms 768 KB Output is correct
19 Correct 715 ms 748 KB Output is correct
20 Correct 600 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 631 ms 1024 KB Output is correct
2 Correct 603 ms 1024 KB Output is correct
3 Correct 1194 ms 768 KB Output is correct
4 Correct 824 ms 904 KB Output is correct
5 Correct 695 ms 768 KB Output is correct
6 Correct 567 ms 1024 KB Output is correct
7 Correct 572 ms 904 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 613 ms 896 KB Output is correct
12 Correct 656 ms 760 KB Output is correct
13 Correct 974 ms 752 KB Output is correct
14 Correct 833 ms 768 KB Output is correct
15 Correct 664 ms 640 KB Output is correct
16 Correct 513 ms 804 KB Output is correct
17 Correct 877 ms 876 KB Output is correct
18 Correct 604 ms 1024 KB Output is correct
19 Correct 500 ms 992 KB Output is correct
20 Correct 412 ms 928 KB Output is correct
21 Correct 53 ms 768 KB Output is correct
22 Correct 80 ms 896 KB Output is correct
23 Correct 108 ms 768 KB Output is correct
24 Correct 8 ms 776 KB Output is correct
25 Correct 4 ms 640 KB Output is correct
26 Correct 5 ms 640 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 2 ms 656 KB Output is correct
29 Correct 618 ms 640 KB Output is correct
30 Correct 629 ms 640 KB Output is correct
31 Correct 588 ms 904 KB Output is correct
32 Correct 584 ms 904 KB Output is correct
33 Correct 599 ms 640 KB Output is correct
34 Correct 400 ms 1024 KB Output is correct
35 Correct 563 ms 1008 KB Output is correct
36 Correct 630 ms 984 KB Output is correct
37 Correct 459 ms 768 KB Output is correct
38 Correct 603 ms 832 KB Output is correct
39 Correct 544 ms 768 KB Output is correct
40 Correct 566 ms 1008 KB Output is correct
41 Correct 505 ms 852 KB Output is correct
42 Correct 85 ms 768 KB Output is correct
43 Correct 127 ms 776 KB Output is correct
44 Correct 144 ms 768 KB Output is correct
45 Correct 163 ms 896 KB Output is correct
46 Correct 339 ms 948 KB Output is correct
47 Correct 409 ms 780 KB Output is correct
48 Correct 65 ms 768 KB Output is correct
49 Correct 94 ms 768 KB Output is correct