답안 #622593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
622593 2022-08-04T12:04:01 Z erekle 기지국 (IOI20_stations) C++17
100 / 100
972 ms 744 KB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> g;
vector<int> tin, tout, depth;
int t;
void dfs(int node, int parent = -1) {
	if (parent == -1) depth[node] = 0;
	else depth[node] = depth[parent] + 1;

	tin[node] = ++t;
	for (int child : g[node]) {
		if (child != parent) dfs(child, node);
	}
	tout[node] = ++t;
}

void compress(vector<int> &v) {
	vector<int> u = v;
	sort(u.begin(), u.end());
	// all values already unique
	for (int &x : v) {
		x = lower_bound(u.begin(), u.end(), x) - u.begin();
	}
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	g.clear(), tin.clear(), tout.clear(), depth.clear();
	g.resize(n);
	for (int i = 0; i < u.size(); ++i) {
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}
	t = -1;
	tin.resize(n), tout.resize(n);
	depth.resize(n);
	dfs(0);

	vector<int> labels(n);
	for (int i = 0; i < n; i++) {
		if (depth[i] & 1) labels[i] = tout[i];
		else labels[i] = tin[i];
	}
	compress(labels);
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	int m = c.size();
	if (m == 1) return c[0];
	sort(c.begin(), c.end());
	if (s < c.front()) { // s has tin, rest have tout
		// c.back() is parent of s
		if (s <= t && t <= c[m-2]) {
			// t is in subtree of s
			// which child
			for (int x : c) {
				if (t <= x) return x;
			}
		} else {
			// t is not in subtree of s
			return c.back();
		}
	} else { // s has tout, rest have tin
		// c.front() is parent of s
		if (c[1] <= t && t <= s) {
			// t is in subtree of s
			// which child
			for (int i = m-1; i >= 0; --i) {
				if (t >= c[i]) return c[i];
			}
		} else {
			// t is not in subtree of s
			return c.front();
		}
	}
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:32:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for (int i = 0; i < u.size(); ++i) {
      |                  ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:79:1: warning: control reaches end of non-void function [-Wreturn-type]
   79 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 536 ms 636 KB Output is correct
2 Correct 443 ms 548 KB Output is correct
3 Correct 858 ms 416 KB Output is correct
4 Correct 623 ms 500 KB Output is correct
5 Correct 548 ms 500 KB Output is correct
6 Correct 434 ms 628 KB Output is correct
7 Correct 418 ms 544 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 4 ms 500 KB Output is correct
10 Correct 3 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 351 ms 628 KB Output is correct
2 Correct 436 ms 548 KB Output is correct
3 Correct 912 ms 416 KB Output is correct
4 Correct 643 ms 416 KB Output is correct
5 Correct 577 ms 420 KB Output is correct
6 Correct 431 ms 548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 538 ms 636 KB Output is correct
2 Correct 416 ms 640 KB Output is correct
3 Correct 852 ms 504 KB Output is correct
4 Correct 670 ms 416 KB Output is correct
5 Correct 532 ms 416 KB Output is correct
6 Correct 402 ms 500 KB Output is correct
7 Correct 402 ms 548 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 588 ms 416 KB Output is correct
12 Correct 465 ms 712 KB Output is correct
13 Correct 445 ms 704 KB Output is correct
14 Correct 410 ms 548 KB Output is correct
15 Correct 44 ms 480 KB Output is correct
16 Correct 48 ms 580 KB Output is correct
17 Correct 84 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 972 ms 500 KB Output is correct
2 Correct 586 ms 508 KB Output is correct
3 Correct 633 ms 420 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 0 ms 500 KB Output is correct
7 Correct 620 ms 504 KB Output is correct
8 Correct 906 ms 416 KB Output is correct
9 Correct 636 ms 544 KB Output is correct
10 Correct 479 ms 416 KB Output is correct
11 Correct 4 ms 500 KB Output is correct
12 Correct 4 ms 492 KB Output is correct
13 Correct 4 ms 496 KB Output is correct
14 Correct 2 ms 500 KB Output is correct
15 Correct 2 ms 500 KB Output is correct
16 Correct 467 ms 420 KB Output is correct
17 Correct 547 ms 504 KB Output is correct
18 Correct 479 ms 420 KB Output is correct
19 Correct 493 ms 420 KB Output is correct
20 Correct 479 ms 416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 538 ms 672 KB Output is correct
2 Correct 506 ms 544 KB Output is correct
3 Correct 721 ms 416 KB Output is correct
4 Correct 661 ms 544 KB Output is correct
5 Correct 607 ms 416 KB Output is correct
6 Correct 436 ms 500 KB Output is correct
7 Correct 503 ms 504 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 525 ms 636 KB Output is correct
12 Correct 502 ms 544 KB Output is correct
13 Correct 775 ms 416 KB Output is correct
14 Correct 658 ms 508 KB Output is correct
15 Correct 571 ms 416 KB Output is correct
16 Correct 396 ms 548 KB Output is correct
17 Correct 584 ms 420 KB Output is correct
18 Correct 446 ms 744 KB Output is correct
19 Correct 438 ms 620 KB Output is correct
20 Correct 484 ms 512 KB Output is correct
21 Correct 35 ms 420 KB Output is correct
22 Correct 81 ms 640 KB Output is correct
23 Correct 100 ms 592 KB Output is correct
24 Correct 5 ms 492 KB Output is correct
25 Correct 5 ms 492 KB Output is correct
26 Correct 4 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 548 ms 420 KB Output is correct
30 Correct 495 ms 416 KB Output is correct
31 Correct 486 ms 504 KB Output is correct
32 Correct 475 ms 416 KB Output is correct
33 Correct 433 ms 416 KB Output is correct
34 Correct 391 ms 544 KB Output is correct
35 Correct 645 ms 692 KB Output is correct
36 Correct 610 ms 712 KB Output is correct
37 Correct 515 ms 624 KB Output is correct
38 Correct 482 ms 704 KB Output is correct
39 Correct 421 ms 712 KB Output is correct
40 Correct 409 ms 688 KB Output is correct
41 Correct 420 ms 596 KB Output is correct
42 Correct 54 ms 544 KB Output is correct
43 Correct 113 ms 604 KB Output is correct
44 Correct 149 ms 544 KB Output is correct
45 Correct 149 ms 508 KB Output is correct
46 Correct 350 ms 508 KB Output is correct
47 Correct 380 ms 504 KB Output is correct
48 Correct 72 ms 652 KB Output is correct
49 Correct 53 ms 620 KB Output is correct