Submission #1080550

# Submission time Handle Problem Language Result Execution time Memory
1080550 2024-08-29T10:52:35 Z Faisal_Saqib Stations (IOI20_stations) C++17
100 / 100
633 ms 1188 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int N=1e3+100;
const int M=1e3;
vector<int> ma[N];
int tin[N],tout[N],last[N],timer=-1;
void dfs(int v, int p,int h=0)
{
    tin[v] = ++timer; // n

    for (auto u:ma[v]) {
        if (u != p)
        {
            dfs(u, v,1-h);
        }
    }
   	last[v]=h;
    tout[v] = ++timer; // n
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	timer=-1;
	for(int i=0;i<(n);i++)last[i]=-1,ma[i].clear();
	vector<int> labels(n,0);
	for(int i=0;i<(n-1);i++)
	{
		ma[u[i]].push_back(v[i]);
		ma[v[i]].push_back(u[i]);
	}
	dfs(0,-1);
	// tout[i] >= tin[i]
	// tout[i]-tin[i] == sz[i]
	// 1<= sz[i] <=n

	for(int i=0;i<n;i++)
	{
		if(last[i]==0)
		{
			labels[i]=tin[i];
		}
		else
		{
			labels[i]=tout[i];
		}
	}
	sort(begin(labels),end(labels));
	vector<int> ans(n);
	for(int i=0;i<n;i++)
	{
		if(last[i]==0)
		{
			ans[i]=lower_bound(begin(labels),end(labels),tin[i])-begin(labels);
		}
		else
		{
			ans[i]=lower_bound(begin(labels),end(labels),tout[i])-begin(labels);
		}
	}
	return ans;
}
int find_next_station(int s, int t, std::vector<int> c) {
	sort(begin(c),end(c));
	if(s<c[0])
	{
		// s = in[s]
		int last=s+1;
		for(auto j:c)
		{
			if(last<=t and t<=j)
				return j;
			last=j+1;
		}
		return c.back();
	}
	else
	{
		reverse(begin(c),end(c));
		int last=s-1;
		for(auto j:c)
		{
			if(j<=t and t<=last)
				return j;
			last=j-1;
		}
		return c.back();
	}
	return t;
}
# Verdict Execution time Memory Grader output
1 Correct 390 ms 684 KB Output is correct
2 Correct 308 ms 940 KB Output is correct
3 Correct 624 ms 688 KB Output is correct
4 Correct 432 ms 684 KB Output is correct
5 Correct 392 ms 684 KB Output is correct
6 Correct 340 ms 684 KB Output is correct
7 Correct 343 ms 684 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 315 ms 684 KB Output is correct
2 Correct 362 ms 684 KB Output is correct
3 Correct 618 ms 688 KB Output is correct
4 Correct 442 ms 684 KB Output is correct
5 Correct 400 ms 684 KB Output is correct
6 Correct 313 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 387 ms 944 KB Output is correct
2 Correct 305 ms 940 KB Output is correct
3 Correct 578 ms 684 KB Output is correct
4 Correct 461 ms 684 KB Output is correct
5 Correct 409 ms 688 KB Output is correct
6 Correct 339 ms 684 KB Output is correct
7 Correct 315 ms 684 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 3 ms 772 KB Output is correct
10 Correct 1 ms 760 KB Output is correct
11 Correct 391 ms 684 KB Output is correct
12 Correct 328 ms 932 KB Output is correct
13 Correct 305 ms 932 KB Output is correct
14 Correct 335 ms 688 KB Output is correct
15 Correct 30 ms 768 KB Output is correct
16 Correct 50 ms 768 KB Output is correct
17 Correct 69 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 633 ms 684 KB Output is correct
2 Correct 448 ms 684 KB Output is correct
3 Correct 389 ms 684 KB Output is correct
4 Correct 2 ms 776 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 0 ms 768 KB Output is correct
7 Correct 408 ms 684 KB Output is correct
8 Correct 616 ms 684 KB Output is correct
9 Correct 478 ms 684 KB Output is correct
10 Correct 446 ms 684 KB Output is correct
11 Correct 3 ms 764 KB Output is correct
12 Correct 5 ms 772 KB Output is correct
13 Correct 3 ms 776 KB Output is correct
14 Correct 3 ms 776 KB Output is correct
15 Correct 1 ms 776 KB Output is correct
16 Correct 384 ms 684 KB Output is correct
17 Correct 259 ms 684 KB Output is correct
18 Correct 305 ms 684 KB Output is correct
19 Correct 290 ms 684 KB Output is correct
20 Correct 311 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 338 ms 1064 KB Output is correct
2 Correct 276 ms 684 KB Output is correct
3 Correct 629 ms 684 KB Output is correct
4 Correct 486 ms 684 KB Output is correct
5 Correct 364 ms 684 KB Output is correct
6 Correct 329 ms 684 KB Output is correct
7 Correct 325 ms 684 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 2 ms 776 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 315 ms 684 KB Output is correct
12 Correct 360 ms 684 KB Output is correct
13 Correct 631 ms 684 KB Output is correct
14 Correct 420 ms 684 KB Output is correct
15 Correct 424 ms 684 KB Output is correct
16 Correct 269 ms 688 KB Output is correct
17 Correct 363 ms 684 KB Output is correct
18 Correct 313 ms 796 KB Output is correct
19 Correct 308 ms 788 KB Output is correct
20 Correct 323 ms 684 KB Output is correct
21 Correct 27 ms 768 KB Output is correct
22 Correct 46 ms 768 KB Output is correct
23 Correct 49 ms 716 KB Output is correct
24 Correct 3 ms 768 KB Output is correct
25 Correct 2 ms 768 KB Output is correct
26 Correct 3 ms 764 KB Output is correct
27 Correct 2 ms 768 KB Output is correct
28 Correct 1 ms 760 KB Output is correct
29 Correct 324 ms 940 KB Output is correct
30 Correct 360 ms 936 KB Output is correct
31 Correct 336 ms 684 KB Output is correct
32 Correct 334 ms 684 KB Output is correct
33 Correct 361 ms 684 KB Output is correct
34 Correct 208 ms 684 KB Output is correct
35 Correct 260 ms 1188 KB Output is correct
36 Correct 297 ms 936 KB Output is correct
37 Correct 320 ms 792 KB Output is correct
38 Correct 331 ms 932 KB Output is correct
39 Correct 328 ms 804 KB Output is correct
40 Correct 302 ms 800 KB Output is correct
41 Correct 305 ms 800 KB Output is correct
42 Correct 34 ms 744 KB Output is correct
43 Correct 79 ms 688 KB Output is correct
44 Correct 110 ms 684 KB Output is correct
45 Correct 107 ms 684 KB Output is correct
46 Correct 214 ms 684 KB Output is correct
47 Correct 215 ms 684 KB Output is correct
48 Correct 32 ms 764 KB Output is correct
49 Correct 34 ms 1164 KB Output is correct