제출 #1356267

#제출 시각아이디문제언어결과실행 시간메모리
1356267crispxx기지국 (IOI20_stations)C++20
100 / 100
290 ms552 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> lbl(n), d(n);
	
	int timer = 0;
	
	auto dfs = [&](auto &&self, int v, int p) -> void {
		if(~d[v] & 1) lbl[v] = timer++;
		
		for(auto to : adj[v]) {
			if(to == p) continue;
			
			d[to] = d[v] + 1;
			
			self(self, to, v);
		}
		
		if(d[v] & 1) lbl[v] = timer++; 
	};
	
	dfs(dfs, 0, 0);
	
	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));
	}
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…