Submission #1194685

#TimeUsernameProblemLanguageResultExecution timeMemory
1194685h1440Stations (IOI20_stations)C++20
100 / 100
306 ms588 KiB
// #include "stations.h"
#include <bits/stdc++.h>
#define fore(i,a,b) for(lli i = (a), abcdxd = (b); i < abcdxd; i++)
#define sz(s) (lli((s).size()))
#define all(v) (v).begin(), (v).end()
#define pb push_back
using namespace std;
typedef int lli;
typedef vector<lli> vi;

// const lli N = 1e3 + 5;

vector<vi> adj;
vi tk;

lli tim;

void dfs(lli u, lli p, lli w){
	if (w == 0) tk[u] = tim++;
	for(auto & i : adj[u]) if (i != p) dfs(i, u, 1-w);
	if (w == 1) tk[u] = tim++;
	// cout << u << ": " << tim << endl;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	tk.resize(n);
	adj.resize(n+5);
	for (auto &i : adj) i.clear();
	fore(i,0,n-1){
		lli a = u[i], b = v[i];
		adj[a].pb(b);
		adj[b].pb(a);
	}
	tim = 0;
	dfs(1, -1, 0);
	return tk;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if (s < c[0]){
		fore(i,0,sz(c)-1) if (s < t and t <= c[i]) return c[i];
		return c[sz(c)-1];
	}
	else{
		for (lli i = sz(c) - 1; i > 0; i--) if (c[i] <= t and t < s) return c[i];
		return c[0];
	}
	return 0;
}
#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...