Submission #305143

# Submission time Handle Problem Language Result Execution time Memory
305143 2020-09-22T15:53:53 Z Temmie Stations (IOI20_stations) C++17
0 / 100
985 ms 1028 KB
#include <bits/stdc++.h>

struct Node {
	std::vector <int> nei;
	int d, a, b;
	Node() : d(0), a(0), b(0) { }
};

struct Triplet {
	int x, y, z;
	Triplet(int X = 0, int Y = 0, int Z = 0) : x(X), y(Y), z(Z) { }
	bool operator<(const Triplet& other) const {
		if (x == other.x) return y > other.y;
		return x < other.x;
	}
};

void dfs(std::vector <Node>& g, int node = 0, int par = -1) {
	static int cnt = 0;
	if (!node) cnt = 0;
	g[node].a = cnt++;
	g[node].d = par == -1 ? 0 : g[par].d + 1;
	for (int x : g[node].nei) if (x != par) dfs(g, x, node);
	g[node].b = cnt - 1;
}

std::vector <int> label(int n, int k, std::vector <int> u, std::vector <int> v) {
	
	std::vector <int> r(n);
	std::vector <Node> g(n);
	for (int i = 0; i < n - 1; i++) {
		g[u[i]].nei.push_back(v[i]);
		g[v[i]].nei.push_back(u[i]);
	}
	dfs(g);
	std::vector <Triplet> tr(n);
	for (int i = 0; i < n; i++) tr[i] = Triplet(g[i].d & 1 ? g[i].b : g[i].a, g[i].d, i);
	std::sort(tr.begin(), tr.end());
	for (int i = 0; i < n; i++) r[tr[i].z] = i;
	return r;
	
}

int find_next_station(int s, int t, std::vector <int> c) {
	if (!(c.size() - 1)) return c.front();
	if (!s) for (int x : c) if (x >= t) return x;
	if (s < c.front()) {
		if (!(s <= t && t <= c[c.size() - 2])) return c.back();
		for (int x : c) if (x >= t) return x;
	}
	if (!(s <= t && c[1] <= t)) return c.front();
	for (int i = (int)c.size() - 1; i >= 0; i--) if (t >= c[i]) return c[i];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 632 ms 984 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 630 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 649 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 985 ms 776 KB Output is correct
2 Incorrect 730 ms 812 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 554 ms 1028 KB Wrong query response.
2 Halted 0 ms 0 KB -