Submission #407278

# Submission time Handle Problem Language Result Execution time Memory
407278 2021-05-18T17:11:09 Z Dilshod_Imomov Stations (IOI20_stations) C++17
0 / 100
3000 ms 2097156 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e3 + 7;

int cnt, lb[MAXN];
vector < int > adj[MAXN];

void dfs( int v, int p ) {
	lb[v] = cnt++;
	for ( auto u: adj[v] ) {
		if ( u != p ) {
			dfs( u, v );
		}
	}
	if ( p != -1 ) {
		lb[v] *= 1000;
		lb[v] += cnt;
	}
	else {
		lb[v] *= 1000;
		lb[v]++;
	}
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	for ( int i = 0; i < n - 1; i++ ) {
		adj[ u[i] ].push_back( v[i] );
		adj[ v[i] ].push_back( u[i] );
	}
	int mx = 0, rt = -1;
	for ( int i = 0; i < n; i++ ) {
		if ( (int)adj[i].size() > mx ) {
			mx = adj[i].size();
			rt = i;
		}
	}
	cnt = 0;
	dfs( rt, -1 );
	vector < int > lbs;
	for ( int i = 0; i < n; i++ ) {
		lbs.push_back( lb[i] );
	}
	return lbs;
}

int find_next_station(int s, int t, std::vector<int> c) {
	int i = s / 1000;
	int j = t / 1000;
	if ( s == 1 ) {
		for ( auto v: c ) {
			int x = v / 1000, y = v % 1000;
			if ( j >= x && j <= y ) {
				return v;
			}
		}
	}
	int pr = -1;
	for ( auto v: c ) {
		int x = v / 1000, y = v % 1000;
		if ( x < i ) {
			pr = v;
		}
		if ( j >= x && j <= y ) {
			return v;
		}
	}
	return pr;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1226 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3058 ms 416 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1354 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 973 ms 492 KB Output is correct
2 Runtime error 1129 ms 2097156 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2366 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -