제출 #959072

#제출 시각아이디문제언어결과실행 시간메모리
959072The_SamuraiStations (IOI20_stations)C++17
100 / 100
603 ms1408 KiB
#include "stations.h"
#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);
	vector<bool> vis(n);
	for (int i = 0; i < n - 1; i++) {
		adj[u[i]].emplace_back(v[i]);
		adj[v[i]].emplace_back(u[i]);
	}
	int z = 0;
	vector<int> h(n), tin(n), tout(n), ans(n);
	auto dfs = [&](auto &dfs, int u) -> void {
		if (h[u] % 2 == 0) tin[u] = z++;
		vis[u] = true;
		for (int v: adj[u]) {
			if (vis[v]) continue;
			h[v] = h[u] + 1;
			dfs(dfs, v);
		}
		if (h[u] % 2) tout[u] = z++;
	};
	dfs(dfs, 0);
	for (int i = 0; i < n; i++) ans[i] = h[i] % 2 ? tout[i] : tin[i];
	// for (int i = 0; i < n; i++) cout << ans[i] << ' ';
	// cout << endl;
	return ans;
}


int find_next_station(int s, int t, std::vector<int> c) {
	sort(c.begin(), c.end());
	// cout << '\t' << s << ' ' << t << endl;
	// cout << '\t';
	// for (int u: c) cout << u << ' ';
	// cout << endl;
	bool even = true;
	for (int u: c) even &= u > s;
	if (even) {
		for (int u: c) {
			if (s <= t and t <= u) return u;
		}
		return c.back();
	} else {
		reverse(c.begin(), c.end());
		for (int u: c) {
			if (u == c.back()) return u;
			if (u <= t and t <= s) return u;
		}
	}
}

컴파일 시 표준 에러 (stderr) 메시지

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:52:1: warning: control reaches end of non-void function [-Wreturn-type]
   52 | }
      | ^
#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...