답안 #606845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
606845 2022-07-26T09:09:45 Z Tigryonochekk 기지국 (IOI20_stations) C++17
100 / 100
926 ms 780 KB
#include <iostream>
#include "stations.h"
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
const int N = 1002;

vector<int> g[N];
vector<int> labels;
int tin[N], tout[N];
int timer = 0;
int h[N];

void dfs(int v, int p) {
	tin[v] = timer++;
	for (int to : g[v]) {
		if (p == to) continue;
		h[to] = h[v] + 1;
		dfs(to, v);
	}
	tout[v] = timer++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	labels.resize(n, 0);
	for (int i = 0; i < n; i++) {
		g[i].clear();
	}
	timer = 0;
	fill(h, h + n, 0);
	for (int i = 0; i < n - 1; i++) {
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}
	dfs(0, -1);
	for (int i = 0; i < n; i++) {
		if (h[i] % 2 == 0) {
			labels[i] = tin[i] / 2;
		}
		else {
			labels[i] = tout[i] / 2;
		}
		//cout << i << " " << labels[i] << endl;
	}
	/*vector<int> c = {0, 1, 5};
	cout << *(upper_bound(c.begin() + 1, c.end(), 5) - 1) << endl;
	cout << "____________\n";*/
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	if (c.size() == 1)
		return c[0];
	int n = c.size();
	if (s == 0) {
		return *lower_bound(c.begin(), c.end(), t);
	}
	if (s > c[0]) { // s@ tout a, c[0]-n hern a
		int si = c[1], so = s;
		if (t >= si && t <= so) {
			return *(upper_bound(c.begin() + 1, c.end(), t) - 1);
		}
		else {
			return c[0];
		}
		
	}
	else { //s@ tin a, c[n-1]@ hern a
		int si = s, so = c[n - 2];
		if (t >= si && t <= so) {
			return *lower_bound(c.begin(), c.end(), t);
		}
		else {
			return c.back();
		}
	}
}
/*
1 
12 2000 
0 1 
0 2 
0 3 
1 4 
1 5 
2 6 
3 7 
4 8 
4 9 
7 10 
8 11 
10 
0 6 2 
0 10 3  
8 7 4 
2 8 0  
4 2 1 
7 5 3  
1 5 5 
1 8 4  
4 9 9 
4 11 8 
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 569 ms 656 KB Output is correct
2 Correct 399 ms 712 KB Output is correct
3 Correct 729 ms 592 KB Output is correct
4 Correct 671 ms 548 KB Output is correct
5 Correct 541 ms 544 KB Output is correct
6 Correct 388 ms 528 KB Output is correct
7 Correct 348 ms 544 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 4 ms 628 KB Output is correct
10 Correct 2 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 441 ms 672 KB Output is correct
2 Correct 459 ms 548 KB Output is correct
3 Correct 743 ms 536 KB Output is correct
4 Correct 637 ms 528 KB Output is correct
5 Correct 461 ms 536 KB Output is correct
6 Correct 353 ms 536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 506 ms 640 KB Output is correct
2 Correct 463 ms 544 KB Output is correct
3 Correct 908 ms 572 KB Output is correct
4 Correct 701 ms 572 KB Output is correct
5 Correct 515 ms 420 KB Output is correct
6 Correct 516 ms 548 KB Output is correct
7 Correct 449 ms 536 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 3 ms 620 KB Output is correct
10 Correct 1 ms 632 KB Output is correct
11 Correct 564 ms 528 KB Output is correct
12 Correct 474 ms 636 KB Output is correct
13 Correct 413 ms 652 KB Output is correct
14 Correct 308 ms 532 KB Output is correct
15 Correct 36 ms 620 KB Output is correct
16 Correct 64 ms 600 KB Output is correct
17 Correct 117 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 669 ms 516 KB Output is correct
2 Correct 563 ms 524 KB Output is correct
3 Correct 598 ms 532 KB Output is correct
4 Correct 2 ms 756 KB Output is correct
5 Correct 5 ms 628 KB Output is correct
6 Correct 1 ms 700 KB Output is correct
7 Correct 576 ms 544 KB Output is correct
8 Correct 850 ms 532 KB Output is correct
9 Correct 526 ms 416 KB Output is correct
10 Correct 537 ms 420 KB Output is correct
11 Correct 6 ms 492 KB Output is correct
12 Correct 5 ms 500 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 3 ms 492 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 422 ms 532 KB Output is correct
17 Correct 486 ms 528 KB Output is correct
18 Correct 492 ms 596 KB Output is correct
19 Correct 521 ms 544 KB Output is correct
20 Correct 453 ms 536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 468 ms 544 KB Output is correct
2 Correct 511 ms 664 KB Output is correct
3 Correct 926 ms 416 KB Output is correct
4 Correct 634 ms 528 KB Output is correct
5 Correct 547 ms 416 KB Output is correct
6 Correct 484 ms 544 KB Output is correct
7 Correct 445 ms 568 KB Output is correct
8 Correct 3 ms 488 KB Output is correct
9 Correct 3 ms 500 KB Output is correct
10 Correct 0 ms 620 KB Output is correct
11 Correct 402 ms 548 KB Output is correct
12 Correct 363 ms 536 KB Output is correct
13 Correct 877 ms 520 KB Output is correct
14 Correct 673 ms 524 KB Output is correct
15 Correct 564 ms 544 KB Output is correct
16 Correct 434 ms 524 KB Output is correct
17 Correct 536 ms 612 KB Output is correct
18 Correct 388 ms 648 KB Output is correct
19 Correct 428 ms 636 KB Output is correct
20 Correct 422 ms 548 KB Output is correct
21 Correct 57 ms 548 KB Output is correct
22 Correct 71 ms 668 KB Output is correct
23 Correct 104 ms 576 KB Output is correct
24 Correct 4 ms 492 KB Output is correct
25 Correct 5 ms 628 KB Output is correct
26 Correct 4 ms 492 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 451 ms 536 KB Output is correct
30 Correct 515 ms 548 KB Output is correct
31 Correct 488 ms 532 KB Output is correct
32 Correct 471 ms 536 KB Output is correct
33 Correct 445 ms 532 KB Output is correct
34 Correct 278 ms 648 KB Output is correct
35 Correct 453 ms 780 KB Output is correct
36 Correct 396 ms 544 KB Output is correct
37 Correct 444 ms 652 KB Output is correct
38 Correct 375 ms 656 KB Output is correct
39 Correct 461 ms 652 KB Output is correct
40 Correct 456 ms 668 KB Output is correct
41 Correct 424 ms 652 KB Output is correct
42 Correct 62 ms 600 KB Output is correct
43 Correct 92 ms 544 KB Output is correct
44 Correct 108 ms 556 KB Output is correct
45 Correct 189 ms 528 KB Output is correct
46 Correct 323 ms 524 KB Output is correct
47 Correct 326 ms 548 KB Output is correct
48 Correct 80 ms 704 KB Output is correct
49 Correct 66 ms 676 KB Output is correct