Submission #306667

# Submission time Handle Problem Language Result Execution time Memory
306667 2020-09-26T05:36:48 Z errorgorn Stations (IOI20_stations) C++17
100 / 100
1166 ms 1536 KB
#include "stations.h"
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
 
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
 
 
//idea is label stores in and out time. this is bounded by 1000**2
 
vector<int> al[1005];
int in[1005];
int out[1005];
int d[1005];
 
int TIME;
void dfs(int i,int p){
	in[i]=++TIME;
	
	for (auto &it:al[i]){
		if (it==p) continue;
		
		d[it]=d[i]+1;
		dfs(it,i);
	}
	out[i]=++TIME;
}
 
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	rep(x,0,1005) al[x].clear();
	
	rep(x,0,n-1){
		al[u[x]].push_back(v[x]);
		al[v[x]].push_back(u[x]);
	}
	
	TIME=-1;
	dfs(0,-1);
	
	vector<int> labels;
	rep(x,0,n){
		if (d[x]%2==0) labels.push_back(in[x]);
		else labels.push_back(out[x]);
	}
	
	vector<int> uni;
	rep(x,0,n) uni.push_back(labels[x]);
	
	sort(all(uni));
	map<int,int> id;
	rep(x,0,n) id[uni[x]]=x;
	
	rep(x,0,n) labels[x]=id[labels[x]];
	
	//rep(x,0,n) cout<<labels[x]<<" "; cout<<endl;
	
	return labels;
}
 
int find_next_station(int s, int t, std::vector<int> c) {
	if (s==0){ //this is for root
		for (auto &it:c){
			if (t<=it) return it;
		}
	}
	else if (c.back()<s){ //this is a outdegree thing, c[0] is parent
		c.push_back(s);
		if (sz(c)>1) rep(x,1,sz(c)-1){
			if (c[x]<=t && t<c[x+1]) return c[x];
		}
		return c[0];
	}
	else{
		if (s<t && t<=c[0]) return c[0];
		if (sz(c)>1) rep(x,0,sz(c)-2){
			if (c[x]<t && t<=c[x+1]) return c[x+1];
		}
		return c.back();
	}
	exit(-1);
	return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 589 ms 1320 KB Output is correct
2 Correct 474 ms 1024 KB Output is correct
3 Correct 916 ms 768 KB Output is correct
4 Correct 786 ms 860 KB Output is correct
5 Correct 593 ms 768 KB Output is correct
6 Correct 525 ms 1024 KB Output is correct
7 Correct 478 ms 1024 KB Output is correct
8 Correct 2 ms 872 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 477 ms 1160 KB Output is correct
2 Correct 550 ms 1008 KB Output is correct
3 Correct 859 ms 1040 KB Output is correct
4 Correct 644 ms 768 KB Output is correct
5 Correct 622 ms 868 KB Output is correct
6 Correct 512 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 546 ms 1008 KB Output is correct
2 Correct 463 ms 1024 KB Output is correct
3 Correct 1166 ms 868 KB Output is correct
4 Correct 898 ms 1024 KB Output is correct
5 Correct 743 ms 864 KB Output is correct
6 Correct 456 ms 1008 KB Output is correct
7 Correct 513 ms 1024 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 872 KB Output is correct
10 Correct 2 ms 872 KB Output is correct
11 Correct 580 ms 768 KB Output is correct
12 Correct 480 ms 1024 KB Output is correct
13 Correct 521 ms 1024 KB Output is correct
14 Correct 512 ms 768 KB Output is correct
15 Correct 53 ms 852 KB Output is correct
16 Correct 68 ms 796 KB Output is correct
17 Correct 103 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1119 ms 768 KB Output is correct
2 Correct 874 ms 860 KB Output is correct
3 Correct 663 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 2 ms 868 KB Output is correct
7 Correct 721 ms 768 KB Output is correct
8 Correct 1012 ms 888 KB Output is correct
9 Correct 735 ms 1024 KB Output is correct
10 Correct 781 ms 768 KB Output is correct
11 Correct 7 ms 876 KB Output is correct
12 Correct 6 ms 768 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 4 ms 876 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
16 Correct 702 ms 768 KB Output is correct
17 Correct 502 ms 768 KB Output is correct
18 Correct 524 ms 864 KB Output is correct
19 Correct 512 ms 860 KB Output is correct
20 Correct 551 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 635 ms 1024 KB Output is correct
2 Correct 514 ms 1024 KB Output is correct
3 Correct 879 ms 856 KB Output is correct
4 Correct 652 ms 768 KB Output is correct
5 Correct 578 ms 1024 KB Output is correct
6 Correct 549 ms 1008 KB Output is correct
7 Correct 435 ms 1008 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 4 ms 868 KB Output is correct
10 Correct 1 ms 872 KB Output is correct
11 Correct 427 ms 768 KB Output is correct
12 Correct 547 ms 1024 KB Output is correct
13 Correct 908 ms 864 KB Output is correct
14 Correct 662 ms 768 KB Output is correct
15 Correct 578 ms 864 KB Output is correct
16 Correct 506 ms 768 KB Output is correct
17 Correct 654 ms 800 KB Output is correct
18 Correct 484 ms 1536 KB Output is correct
19 Correct 618 ms 1024 KB Output is correct
20 Correct 438 ms 1024 KB Output is correct
21 Correct 57 ms 864 KB Output is correct
22 Correct 73 ms 896 KB Output is correct
23 Correct 111 ms 1132 KB Output is correct
24 Correct 7 ms 864 KB Output is correct
25 Correct 5 ms 768 KB Output is correct
26 Correct 6 ms 768 KB Output is correct
27 Correct 5 ms 868 KB Output is correct
28 Correct 3 ms 1024 KB Output is correct
29 Correct 566 ms 988 KB Output is correct
30 Correct 528 ms 1032 KB Output is correct
31 Correct 570 ms 768 KB Output is correct
32 Correct 546 ms 768 KB Output is correct
33 Correct 554 ms 864 KB Output is correct
34 Correct 353 ms 1024 KB Output is correct
35 Correct 498 ms 1204 KB Output is correct
36 Correct 466 ms 1024 KB Output is correct
37 Correct 462 ms 1024 KB Output is correct
38 Correct 518 ms 1008 KB Output is correct
39 Correct 580 ms 1024 KB Output is correct
40 Correct 497 ms 1028 KB Output is correct
41 Correct 558 ms 1008 KB Output is correct
42 Correct 70 ms 788 KB Output is correct
43 Correct 146 ms 1264 KB Output is correct
44 Correct 145 ms 1024 KB Output is correct
45 Correct 155 ms 1024 KB Output is correct
46 Correct 305 ms 780 KB Output is correct
47 Correct 317 ms 1024 KB Output is correct
48 Correct 68 ms 1024 KB Output is correct
49 Correct 64 ms 1024 KB Output is correct