Submission #398437

#TimeUsernameProblemLanguageResultExecution timeMemory
398437kevinxiehkStations (IOI20_stations)C++17
100 / 100
1214 ms784 KiB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
#define pb emplace_back
using namespace std;
int lb[1005];
vector<int> conn[1005];
bool vi[1005];
int id = 0;
void dfs(int depth, int now) {
	vi[now] = true;
	if(depth % 2 == 0) {
		lb[now] = id;
		id++;
		for(auto x: conn[now]) if(!vi[x]) dfs(depth + 1, x);
	}
	else {
		for(auto x: conn[now]) if(!vi[x]) dfs(depth + 1, x);
		lb[now] = id;
		id++;
	}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	id = 0;
	vector<int> labels(n);
	for (int i = 0; i < n; i++) {
		conn[i].clear();
		vi[i] = false;
	}
	for(int i = 0; i < n - 1; i++) {
		conn[u[i]].pb(v[i]);
		conn[v[i]].pb(u[i]);
	}
	dfs(0, 0);
	for(int i = 0; i < n; i++) {
		labels[i] = lb[i];
	}
	return labels;
}

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];
		}
		int a = 0;
		while(c[a] < t) a++;
		return c[a];
	}
	else{
		if(t > s || t <= c[0]) {
			return c[0];
		}
		int a = c.size() - 1;
		while(c[a] > t) a--;
		return c[a];
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...