Submission #406591

# Submission time Handle Problem Language Result Execution time Memory
406591 2021-05-17T19:20:04 Z priority_queue Stations (IOI20_stations) C++14
100 / 100
1150 ms 696 KB
#include <bits/stdc++.h>

#define forint(i, N) for (int i = 0; i < (N); i++)

using namespace std;

vector<int> value;
vector<bool> visited;

int minval = 0;

void go(vector< vector<int> >& graph, int n, bool odd) {

	visited[n] = true;

	if (odd) {
		for (auto& i : graph[n]) {
			if (!visited[i]) {
				go(graph, i, !odd);
			}
		}
		value[n] = minval;
		minval++;
	}
	else {
		value[n] = minval;
		minval++;
		for (auto& i : graph[n]) {
			if (!visited[i]) {
				go(graph, i, !odd);
			}
		}
	}
	
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector< vector<int> > graph(n);

	visited.clear();
	visited.resize(n);
	fill(visited.begin(), visited.end(), false);

	value.clear();
	value.resize(n);
	fill(value.begin(), value.end(), -1);

	forint(i, n - 1) {
		graph[u[i]].push_back(v[i]);
		graph[v[i]].push_back(u[i]);
	}

	minval = 0;
	go(graph, 0, true);

	return value;
}


int find_next_station(int s, int t, vector<int> c) {

	if (c.size() == 1) {
		return c[0];
	}	
	
	if (s < c[0]) {
		if (t < s || t > c[c.size() - 1]) {
			return c[c.size() - 1];
		}

		if (t <= c[0]) {
			return c[0];
		}
	}
	else {
		if (t > s || t < c[0]) {
			return c[0];
		}
		if (t >= c[c.size() - 1]) {
			return c[c.size() - 1];
		}
	}


	int left = 0;
	int right = c.size() - 1;

	while (left + 1 < right) {
		if (t == c[left] || t == c[right]) {
			return t;
		}

		int mid = (left + right) / 2;
		if (t <= c[mid]) {
			right = mid;
		}
		else {
			left = mid;
		}
	}

	if (t == c[left] || t == c[right]) {
		return t;
	}

	if (s < c[0] ) {
		return c[right];
	}
	return c[left];
}

# Verdict Execution time Memory Grader output
1 Correct 644 ms 528 KB Output is correct
2 Correct 548 ms 528 KB Output is correct
3 Correct 1097 ms 400 KB Output is correct
4 Correct 749 ms 400 KB Output is correct
5 Correct 712 ms 488 KB Output is correct
6 Correct 443 ms 528 KB Output is correct
7 Correct 540 ms 528 KB Output is correct
8 Correct 3 ms 464 KB Output is correct
9 Correct 6 ms 464 KB Output is correct
10 Correct 2 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 658 ms 492 KB Output is correct
2 Correct 628 ms 484 KB Output is correct
3 Correct 1009 ms 400 KB Output is correct
4 Correct 894 ms 468 KB Output is correct
5 Correct 831 ms 400 KB Output is correct
6 Correct 588 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 709 ms 492 KB Output is correct
2 Correct 443 ms 592 KB Output is correct
3 Correct 675 ms 400 KB Output is correct
4 Correct 833 ms 400 KB Output is correct
5 Correct 652 ms 484 KB Output is correct
6 Correct 674 ms 528 KB Output is correct
7 Correct 632 ms 528 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 6 ms 472 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 820 ms 484 KB Output is correct
12 Correct 476 ms 596 KB Output is correct
13 Correct 657 ms 604 KB Output is correct
14 Correct 571 ms 528 KB Output is correct
15 Correct 69 ms 476 KB Output is correct
16 Correct 71 ms 528 KB Output is correct
17 Correct 145 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1150 ms 400 KB Output is correct
2 Correct 806 ms 400 KB Output is correct
3 Correct 643 ms 400 KB Output is correct
4 Correct 3 ms 464 KB Output is correct
5 Correct 5 ms 468 KB Output is correct
6 Correct 2 ms 476 KB Output is correct
7 Correct 615 ms 400 KB Output is correct
8 Correct 903 ms 464 KB Output is correct
9 Correct 849 ms 400 KB Output is correct
10 Correct 635 ms 616 KB Output is correct
11 Correct 5 ms 468 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 5 ms 472 KB Output is correct
14 Correct 5 ms 468 KB Output is correct
15 Correct 3 ms 468 KB Output is correct
16 Correct 621 ms 488 KB Output is correct
17 Correct 526 ms 488 KB Output is correct
18 Correct 560 ms 484 KB Output is correct
19 Correct 541 ms 400 KB Output is correct
20 Correct 524 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 574 ms 588 KB Output is correct
2 Correct 529 ms 496 KB Output is correct
3 Correct 959 ms 400 KB Output is correct
4 Correct 666 ms 400 KB Output is correct
5 Correct 557 ms 400 KB Output is correct
6 Correct 578 ms 528 KB Output is correct
7 Correct 554 ms 484 KB Output is correct
8 Correct 3 ms 476 KB Output is correct
9 Correct 5 ms 468 KB Output is correct
10 Correct 2 ms 448 KB Output is correct
11 Correct 462 ms 528 KB Output is correct
12 Correct 517 ms 508 KB Output is correct
13 Correct 976 ms 400 KB Output is correct
14 Correct 899 ms 484 KB Output is correct
15 Correct 570 ms 488 KB Output is correct
16 Correct 416 ms 528 KB Output is correct
17 Correct 581 ms 484 KB Output is correct
18 Correct 606 ms 528 KB Output is correct
19 Correct 525 ms 600 KB Output is correct
20 Correct 548 ms 528 KB Output is correct
21 Correct 53 ms 476 KB Output is correct
22 Correct 72 ms 528 KB Output is correct
23 Correct 107 ms 656 KB Output is correct
24 Correct 7 ms 468 KB Output is correct
25 Correct 6 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 4 ms 480 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 597 ms 532 KB Output is correct
30 Correct 585 ms 400 KB Output is correct
31 Correct 505 ms 400 KB Output is correct
32 Correct 633 ms 616 KB Output is correct
33 Correct 549 ms 400 KB Output is correct
34 Correct 399 ms 484 KB Output is correct
35 Correct 448 ms 656 KB Output is correct
36 Correct 446 ms 612 KB Output is correct
37 Correct 560 ms 600 KB Output is correct
38 Correct 588 ms 608 KB Output is correct
39 Correct 450 ms 520 KB Output is correct
40 Correct 531 ms 572 KB Output is correct
41 Correct 459 ms 696 KB Output is correct
42 Correct 62 ms 548 KB Output is correct
43 Correct 99 ms 528 KB Output is correct
44 Correct 157 ms 528 KB Output is correct
45 Correct 193 ms 528 KB Output is correct
46 Correct 417 ms 492 KB Output is correct
47 Correct 428 ms 528 KB Output is correct
48 Correct 75 ms 556 KB Output is correct
49 Correct 56 ms 580 KB Output is correct