Submission #416061

# Submission time Handle Problem Language Result Execution time Memory
416061 2021-06-01T21:26:21 Z SuhaibSawalha1 Stations (IOI20_stations) C++17
0 / 100
906 ms 672 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
 
vector<vector<int>> adj;
vector<int> lab, in, out;
int dfst;
 
void dfs (int u = 0, int p = -1, int d = 0) {
	in[u] = dfst++;
	for (int v : adj[u]) {
		if (v ^ p) {
			dfs(v, u, d ^ 1);
		}
	}
	out[u] = dfst++;
	lab[u] = d ? in[u] : out[u];
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	adj.assign(n, {});
	lab.resize(n);
	in.resize(n);
	out.resize(n);
	dfst = 0;
	for (int i = 0; i < n - 1; ++i) {
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	dfs();
	vector<int> j = lab, ii = lab;
	sort(lab.begin(), lab.end());
	for (int i = 0; i < n; ++i) {
		ii[i] = lower_bound(lab.begin(), lab.end(), j[i]) - lab.begin();
	}
	return ii;
}

int find_next_station(int s, int t, vector<int> c) {
	if (c.size() == 1) {
		return c[0];
	}
	if (s < c[0]) { 
		if (t < s) {
			return c.back();
		}
		return *lower_bound(c.begin(), c.end(), t);
	}
	else { 
		if (t > s) {
			return c[0];
		}
		return *(upper_bound(c.begin(), c.end(), t) - 1);
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 665 ms 644 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 524 ms 672 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 578 ms 596 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 906 ms 400 KB Output is correct
2 Correct 779 ms 400 KB Output is correct
3 Correct 805 ms 484 KB Output is correct
4 Correct 4 ms 520 KB Output is correct
5 Incorrect 6 ms 464 KB Wrong query response.
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 569 ms 648 KB Wrong query response.
2 Halted 0 ms 0 KB -