Submission #531840

# Submission time Handle Problem Language Result Execution time Memory
531840 2022-03-01T16:15:57 Z EqualTurtle Stations (IOI20_stations) C++14
100 / 100
939 ms 52652 KB
#include "stations.h"
#include <vector>
using namespace std;

constexpr int MAXN = 1e6 + 7;
vector <int> graf[MAXN];

int order;
int depth[MAXN];
vector<int> labels;
bool odw[MAXN];
void dfs(int w)
{
	odw[w] = true;
	for (int i : graf[w])
	{
		if (odw[i])
			continue;
		depth[i] = depth[w] + 1;
		if (depth[i] % 2 == 0)
			labels[i] = order++;
		dfs(i);
		if (depth[i] % 2 == 1)
			labels[i] = order++;
	}
}

vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
	while (labels.size())
		labels.pop_back();

	for (int i = 0; i < MAXN; i++){
		while(graf[i].size())
			graf[i].pop_back();
		depth[i] = 0;
		odw[i] = false;
	}
	labels.resize(n);
	order = 1;
	

	for (int i = 0; i < (int)u.size(); i++){
		graf[u[i]].push_back(v[i]);
		graf[v[i]].push_back(u[i]);
	}
	dfs(0);
	
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	if (c.size() == 1)
		return c[0];

	for (int i : c)
		if (i == t)
			return i;
	
	if (s > c.back())
	{
		if (t > s)
			return c[0];
		
		for (int i = 1; i < (int)c.size() - 1; i++)
		{
			if (c[i] < t && c[i + 1] > t)
				return c[i];
		}

		if (c.back() < t)
			return c.back();
		return c[0];
	}
	else
	{
		if (t > c[c.size() - 2] || t < s)
			return c.back();
		
		for (int i = 0; i < (int)c.size(); i++)
		{
			if (c[i] > t)
				return c[i];
		}

		return c.back();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 623 ms 52388 KB Output is correct
2 Correct 495 ms 52512 KB Output is correct
3 Correct 838 ms 52364 KB Output is correct
4 Correct 634 ms 52360 KB Output is correct
5 Correct 630 ms 52372 KB Output is correct
6 Correct 553 ms 52492 KB Output is correct
7 Correct 447 ms 52496 KB Output is correct
8 Correct 48 ms 52396 KB Output is correct
9 Correct 50 ms 52420 KB Output is correct
10 Correct 33 ms 52500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 509 ms 52388 KB Output is correct
2 Correct 539 ms 52508 KB Output is correct
3 Correct 934 ms 52384 KB Output is correct
4 Correct 726 ms 52396 KB Output is correct
5 Correct 588 ms 52368 KB Output is correct
6 Correct 452 ms 52368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 576 ms 52488 KB Output is correct
2 Correct 451 ms 52388 KB Output is correct
3 Correct 894 ms 52360 KB Output is correct
4 Correct 694 ms 52368 KB Output is correct
5 Correct 602 ms 52388 KB Output is correct
6 Correct 439 ms 52500 KB Output is correct
7 Correct 466 ms 52396 KB Output is correct
8 Correct 51 ms 52480 KB Output is correct
9 Correct 52 ms 52392 KB Output is correct
10 Correct 35 ms 52428 KB Output is correct
11 Correct 533 ms 52396 KB Output is correct
12 Correct 509 ms 52652 KB Output is correct
13 Correct 458 ms 52496 KB Output is correct
14 Correct 412 ms 52364 KB Output is correct
15 Correct 94 ms 52304 KB Output is correct
16 Correct 113 ms 52448 KB Output is correct
17 Correct 153 ms 52368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 848 ms 52376 KB Output is correct
2 Correct 672 ms 52376 KB Output is correct
3 Correct 672 ms 52396 KB Output is correct
4 Correct 48 ms 52388 KB Output is correct
5 Correct 56 ms 52480 KB Output is correct
6 Correct 33 ms 52460 KB Output is correct
7 Correct 700 ms 52468 KB Output is correct
8 Correct 939 ms 52384 KB Output is correct
9 Correct 700 ms 52372 KB Output is correct
10 Correct 625 ms 52368 KB Output is correct
11 Correct 52 ms 52428 KB Output is correct
12 Correct 51 ms 52472 KB Output is correct
13 Correct 49 ms 52504 KB Output is correct
14 Correct 54 ms 52476 KB Output is correct
15 Correct 40 ms 52400 KB Output is correct
16 Correct 597 ms 52372 KB Output is correct
17 Correct 506 ms 52368 KB Output is correct
18 Correct 540 ms 52372 KB Output is correct
19 Correct 615 ms 52400 KB Output is correct
20 Correct 557 ms 52360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 557 ms 52452 KB Output is correct
2 Correct 481 ms 52396 KB Output is correct
3 Correct 764 ms 52328 KB Output is correct
4 Correct 589 ms 52372 KB Output is correct
5 Correct 500 ms 52372 KB Output is correct
6 Correct 485 ms 52496 KB Output is correct
7 Correct 465 ms 52392 KB Output is correct
8 Correct 49 ms 52412 KB Output is correct
9 Correct 53 ms 52392 KB Output is correct
10 Correct 32 ms 52400 KB Output is correct
11 Correct 528 ms 52468 KB Output is correct
12 Correct 445 ms 52436 KB Output is correct
13 Correct 848 ms 52364 KB Output is correct
14 Correct 589 ms 52364 KB Output is correct
15 Correct 559 ms 52396 KB Output is correct
16 Correct 500 ms 52368 KB Output is correct
17 Correct 591 ms 52392 KB Output is correct
18 Correct 478 ms 52472 KB Output is correct
19 Correct 567 ms 52532 KB Output is correct
20 Correct 432 ms 52368 KB Output is correct
21 Correct 91 ms 52376 KB Output is correct
22 Correct 108 ms 52380 KB Output is correct
23 Correct 132 ms 52472 KB Output is correct
24 Correct 51 ms 52456 KB Output is correct
25 Correct 52 ms 52372 KB Output is correct
26 Correct 53 ms 52408 KB Output is correct
27 Correct 51 ms 52472 KB Output is correct
28 Correct 41 ms 52388 KB Output is correct
29 Correct 504 ms 52412 KB Output is correct
30 Correct 639 ms 52324 KB Output is correct
31 Correct 560 ms 52372 KB Output is correct
32 Correct 597 ms 52392 KB Output is correct
33 Correct 593 ms 52368 KB Output is correct
34 Correct 334 ms 52496 KB Output is correct
35 Correct 472 ms 52468 KB Output is correct
36 Correct 503 ms 52508 KB Output is correct
37 Correct 403 ms 52584 KB Output is correct
38 Correct 538 ms 52536 KB Output is correct
39 Correct 537 ms 52500 KB Output is correct
40 Correct 441 ms 52516 KB Output is correct
41 Correct 549 ms 52416 KB Output is correct
42 Correct 89 ms 52504 KB Output is correct
43 Correct 161 ms 52460 KB Output is correct
44 Correct 182 ms 52484 KB Output is correct
45 Correct 184 ms 52468 KB Output is correct
46 Correct 315 ms 52372 KB Output is correct
47 Correct 323 ms 52396 KB Output is correct
48 Correct 101 ms 52476 KB Output is correct
49 Correct 103 ms 52532 KB Output is correct