제출 #1356253

#제출 시각아이디문제언어결과실행 시간메모리
1356253crispxx기지국 (IOI20_stations)C++20
76 / 100
290 ms564 KiB
#include "stations.h"
#include <vector>

#include <bits/stdc++.h>

using namespace std;

std::vector<int> label(int n, int k, std::vector<int> U, std::vector<int> V) {
	vector<vector<int>> adj(n);
	
	for(int i = 0; i < n - 1; i++) {
		adj[U[i]].push_back(V[i]);
		adj[V[i]].push_back(U[i]);
	}
	vector<int> tin(n), tout(n), d(n);
	
	int timer = 0;
	
	auto dfs = [&](auto &&self, int v, int p) -> void {
		tin[v] = timer++;
		
		for(auto to : adj[v]) {
			if(to == p) continue;
			
			d[to] = d[v] + 1;
			
			self(self, to, v);
		}
		
		tout[v] = timer++;
	};
	
	dfs(dfs, 0, 0);
	
	vector<int> lbl(n);
	
	for(int i = 0; i < n; i++) {
		lbl[i] = (d[i] & 1 ? tout[i] : tin[i]);
	}
	
	return lbl;
}

int find_next_station(int s, int t, std::vector<int> c) {
	sort(c.begin(), c.end());
	
	if(s < c[0]) { // tin
		if(t < s || t > c.back()) return c.back();
		return *lower_bound(c.begin(), c.end(), t);
	} else { // tout
		if(t < c[0] || t > s) return c[0];
		return *(--upper_bound(c.begin(), c.end(), t));
	}
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…