Submission #434090

# Submission time Handle Problem Language Result Execution time Memory
434090 2021-06-20T14:56:00 Z kwongweng Stations (IOI20_stations) C++17
0 / 100
961 ms 784 KB
#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
typedef vector<int> vi;
#define pb push_back

vi g[2000];
vi ans, sz, used;
int cur;

void dfs1(int u = 0, int p = -1, int d = 0){
	for (int v : g[u]){
		if (v == p) continue;
		dfs1(v, u, d+1);
		sz[u] += sz[v] + 1;
	}
}

void dfs2(int u = 0, int p = -1, int d = 0){
	if (d % 2 == 0){
		used[cur] = 1;
		ans[u] = cur;
		while (used[cur]) cur++;
	}else{
		used[cur+sz[u]] = 1;
		ans[u] = cur+sz[u];
		while (used[cur]) cur++;
	}
	for (int v : g[u]){
		if (v == p) continue;
		dfs2(v, u, d+1);
	}
}

vi label(int n, int k, vi u, vi v) {
	cur = 0;
	vi answer; answer.resize(n, 0);
	ans.resize(n, 0); sz.resize(n, 0); used.resize(n, 0);
	for (int i = 0; i < n-1; i++){
		g[u[i]].pb(v[i]);
		g[v[i]].pb(u[i]);
	}
	dfs1();
	dfs2();
	answer = ans;
	ans.clear(); sz.clear(); used.clear();
	for (int i = 0; i < n; i++) g[i].clear();
	return answer;
}

int find_next_station(int s, int t, vi c) {
	int C = c.size();
	if (C==1) return c[0];
	if (s < c[0]){
		if (t < s || t >= c[C-1]) return c[C-1];
		int pos = C-1;
		for (int i = C-2; i >= 0; i--){
			if (t < c[i+1] && t >= c[i]){
				pos = i; break;
			}
		}
		return c[pos];
	}
	if (t > s || t <= c[0]) return c[0];
	int pos = 0;
	for (int i = 1; i < C; i++){
		if (t > c[i-1] && t <= c[i]){
			pos = i; break;
		}
	}
	return c[pos];
}
# Verdict Execution time Memory Grader output
1 Incorrect 546 ms 784 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 514 ms 656 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 656 ms 784 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 961 ms 656 KB Output is correct
2 Correct 751 ms 784 KB Output is correct
3 Incorrect 720 ms 660 KB Wrong query response.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 822 ms 784 KB Wrong query response.
2 Halted 0 ms 0 KB -