Submission #490544

# Submission time Handle Problem Language Result Execution time Memory
490544 2021-11-27T23:03:24 Z mraron Stations (IOI20_stations) C++14
0 / 100
776 ms 624 KB
#include "stations.h"
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;

vector<vector<int>> adj;
vector<int> L, R, lvl;
int ind;
void dfs(int x) {
	L[x]=ind++;
	for(auto i:adj[x]) {
		if(!L[i]) {
			dfs(i);
			lvl[i]=lvl[x]+1;
		}
	}
	R[x]=ind++;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	adj.resize(n);
	for(auto& i:adj) i.clear();
	
	for(int i=0;i<n-1;++i) {
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	
	L.assign(n, 0);
	R.assign(n, 0);
	lvl.assign(n, 0);
	ind=1;
	dfs(0);
	
	std::vector<int> labels(n);
	for (int i = 0; i < n; i++) {
		labels[i] = lvl[i]&1?L[i]:R[i];
	}
	
	return labels;
}

bool contains(int a, int b, int x) {
	return min(a, b)<=x && x<=max(a, b);
}


int find_next_station(int s, int t, std::vector<int> c) {
	int best=-1;
	for(int i:c) {
		if(contains(s, i, t)) {
			if(best==-1 || abs(best-s)>abs(s-i)) best=i;
		}
	}
	
	if(best==-1) {
		for(int i:c) {
			if(best==-1 || abs(best-s)<abs(s-i)) best=i;
		}
	}
	
	return best;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 320 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=0, label=1996
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 404 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1992
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 483 ms 624 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 776 ms 400 KB Output is correct
2 Correct 621 ms 492 KB Output is correct
3 Incorrect 536 ms 488 KB Wrong query response.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 497 ms 620 KB Wrong query response.
2 Halted 0 ms 0 KB -