답안 #396042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
396042 2021-04-29T11:56:29 Z InternetPerson10 기지국 (IOI20_stations) C++17
0 / 100
3000 ms 2097156 KB
#include "stations.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<vector<int>> adj;
vector<int> sub;
vector<int> labels;

int sub_calc(int v, int par) {
	int ans = 1;
	for(int i = 0; i < (int)adj[v].size(); i++) {
		if(adj[v][i] == par) continue;
		ans += sub_calc(adj[v][i], v);
	}
	return sub[v] = ans;
}

void rec(int v, int l, int u, int par, int d) { // even: min, odd: max
	if(d%2) { 
		labels[v] = u-1;
		u--;
	}
	else {
		labels[v] = l;
		l++;
	}
	for(int i = 0; i < (int)adj[v].size(); i++) {
		if(adj[v][i] == par) continue;
		rec(adj[v][i], l, l + sub[adj[v][i]], v, d+1);
		l += sub[adj[v][i]];
	}
	return;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	adj.resize(n);
	sub.resize(n);
	labels.resize(n);
	for(int i = 0; i < n-1; i++) {
		int x = u[i];
		int y = v[i];
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	sub_calc(0, -1);
	rec(0, 0, n, -1, 0);
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	if(s < c[0]) {
		sort(c.begin(), c.end());
		if(t < s) return c[c.size() - 1];
		for(int i = 0; i < (int)c.size(); i++) {
			if(t <= c[i]) return c[i];
		}
		return c[c.size()-1];
	}
	else {
		sort(c.rbegin(), c.rend());
		if(t >= s) return c[c.size() - 1];
		for(int i = 0; i < (int)c.size(); i++) {
			if(t >= c[i]) return c[i];
		}
		return c[c.size()-1];
	}
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 404 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3073 ms 2080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1792 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 887 ms 472 KB Output is correct
2 Runtime error 1058 ms 2097156 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2259 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -