Submission #601904

# Submission time Handle Problem Language Result Execution time Memory
601904 2022-07-22T12:03:51 Z yutabi Stations (IOI20_stations) C++14
100 / 100
914 ms 832 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;


#define pb push_back


int n;

vector <vector <int> > tree;
vector <int> ans;
vector <int> sz;


int DFS0(int node, int par)
{
	int sum=1;

	for(int i=0;i<tree[node].size();i++)
	{
		if(tree[node][i]!=par)
		{
			sum+=DFS0(tree[node][i],node);
		}
	}

	sz[node]=sum;

	return sum;
}

void DFS(int l, int r, int node, int par, int mode)
{
	if(mode==0)
	{
		ans[node]=l;

		l++;
	}

	else
	{
		ans[node]=r;

		r--;
	}

	for(int i=0;i<tree[node].size();i++)
	{
		if(tree[node][i]!=par)
		{
			if(mode==0)
			{
				DFS(l,l+sz[tree[node][i]]-1,tree[node][i],node,1);

				l+=sz[tree[node][i]];
			}

			else
			{
				DFS(r-sz[tree[node][i]]+1,r,tree[node][i],node,0);

				r-=sz[tree[node][i]];
			}
		}
	}

	return;
}



std::vector<int> label(int _n, int k, std::vector<int> u, std::vector<int> v)
{
	n=_n;

	tree.clear();
	tree.resize(n);
	ans.resize(n);
	sz.resize(n);

	for(int i=0;i<n-1;i++)
	{
		tree[u[i]].pb(v[i]);
		tree[v[i]].pb(u[i]);
	}

	DFS0(0,-1);
	DFS(0,k-1,0,-1,0);

	/*printf("\n");

	for(int i=0;i<n;i++)
	{
		printf("%d ",ans[i]);
	}

	printf("\n\n");*/

	return ans;
}

int find_next_station(int s, int t, std::vector<int> c)
{
	if(s<c[0])
	{
		if(t<s)
		{
			return c.back();
		}

		for(int i=0;i<c.size();i++)
		{
			if(t<=c[i])
			{
				return c[i];
			}
		}

		return c.back();
	}

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

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

	return c[0];
}

Compilation message

stations.cpp: In function 'int DFS0(int, int)':
stations.cpp:20:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i=0;i<tree[node].size();i++)
      |              ~^~~~~~~~~~~~~~~~~~
stations.cpp: In function 'void DFS(int, int, int, int, int)':
stations.cpp:49:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for(int i=0;i<tree[node].size();i++)
      |              ~^~~~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:113:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |   for(int i=0;i<c.size();i++)
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 472 ms 620 KB Output is correct
2 Correct 487 ms 620 KB Output is correct
3 Correct 907 ms 480 KB Output is correct
4 Correct 591 ms 500 KB Output is correct
5 Correct 549 ms 504 KB Output is correct
6 Correct 410 ms 632 KB Output is correct
7 Correct 536 ms 624 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 420 ms 608 KB Output is correct
2 Correct 492 ms 492 KB Output is correct
3 Correct 914 ms 508 KB Output is correct
4 Correct 689 ms 416 KB Output is correct
5 Correct 585 ms 416 KB Output is correct
6 Correct 354 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 562 ms 676 KB Output is correct
2 Correct 452 ms 616 KB Output is correct
3 Correct 806 ms 424 KB Output is correct
4 Correct 615 ms 544 KB Output is correct
5 Correct 577 ms 508 KB Output is correct
6 Correct 397 ms 648 KB Output is correct
7 Correct 430 ms 636 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 578 ms 560 KB Output is correct
12 Correct 514 ms 832 KB Output is correct
13 Correct 455 ms 712 KB Output is correct
14 Correct 460 ms 508 KB Output is correct
15 Correct 41 ms 444 KB Output is correct
16 Correct 84 ms 564 KB Output is correct
17 Correct 121 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 854 ms 492 KB Output is correct
2 Correct 644 ms 420 KB Output is correct
3 Correct 646 ms 416 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 7 ms 500 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 596 ms 420 KB Output is correct
8 Correct 781 ms 420 KB Output is correct
9 Correct 673 ms 420 KB Output is correct
10 Correct 614 ms 416 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 492 KB Output is correct
13 Correct 4 ms 500 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 507 ms 508 KB Output is correct
17 Correct 485 ms 512 KB Output is correct
18 Correct 437 ms 508 KB Output is correct
19 Correct 499 ms 420 KB Output is correct
20 Correct 514 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 523 ms 632 KB Output is correct
2 Correct 477 ms 676 KB Output is correct
3 Correct 878 ms 480 KB Output is correct
4 Correct 591 ms 504 KB Output is correct
5 Correct 511 ms 416 KB Output is correct
6 Correct 456 ms 544 KB Output is correct
7 Correct 368 ms 552 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 443 ms 500 KB Output is correct
12 Correct 463 ms 536 KB Output is correct
13 Correct 725 ms 512 KB Output is correct
14 Correct 659 ms 504 KB Output is correct
15 Correct 596 ms 416 KB Output is correct
16 Correct 425 ms 504 KB Output is correct
17 Correct 565 ms 512 KB Output is correct
18 Correct 481 ms 624 KB Output is correct
19 Correct 452 ms 628 KB Output is correct
20 Correct 327 ms 552 KB Output is correct
21 Correct 45 ms 444 KB Output is correct
22 Correct 60 ms 544 KB Output is correct
23 Correct 106 ms 544 KB Output is correct
24 Correct 4 ms 492 KB Output is correct
25 Correct 5 ms 492 KB Output is correct
26 Correct 5 ms 492 KB Output is correct
27 Correct 4 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 544 ms 508 KB Output is correct
30 Correct 462 ms 532 KB Output is correct
31 Correct 444 ms 512 KB Output is correct
32 Correct 451 ms 500 KB Output is correct
33 Correct 549 ms 416 KB Output is correct
34 Correct 348 ms 672 KB Output is correct
35 Correct 486 ms 624 KB Output is correct
36 Correct 547 ms 716 KB Output is correct
37 Correct 475 ms 700 KB Output is correct
38 Correct 517 ms 728 KB Output is correct
39 Correct 474 ms 712 KB Output is correct
40 Correct 448 ms 716 KB Output is correct
41 Correct 400 ms 636 KB Output is correct
42 Correct 55 ms 496 KB Output is correct
43 Correct 109 ms 504 KB Output is correct
44 Correct 109 ms 600 KB Output is correct
45 Correct 171 ms 508 KB Output is correct
46 Correct 261 ms 504 KB Output is correct
47 Correct 267 ms 544 KB Output is correct
48 Correct 53 ms 600 KB Output is correct
49 Correct 61 ms 676 KB Output is correct