Submission #416828

# Submission time Handle Problem Language Result Execution time Memory
416828 2021-06-03T03:29:12 Z Dilshod_Imomov Stations (IOI20_stations) C++17
0 / 100
954 ms 55508 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
 
const int MAXN = 1e3 + 7;

vector < int > tin, tout, d;
 
void dfs( vector<vector<int>> adj, int v, int p, int h, int &cnt ) {
	tin[v] = cnt++;
	d[v] = h;
	for ( auto u: adj[v] ) {
		if ( u != p ) {
			dfs( adj, u, v, h + 1, cnt );
		}
	}
	tout[v] = cnt++;
}
 
 
vector<int> label(int n, int k, vector<int> U, vector<int> V) {
	vector < vector < int > > adj(n + 1);
	tin.resize( n + 1 );
	tout.resize( n + 1 );
	d.resize( n + 1 );
	for ( int i = 0; i < n - 1; i++ ) {
		int u = U[i], v = V[i];
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	vector < int > lb(n);
	int cnt = 0;
	dfs( adj, 0, -1, 0, cnt );
	vector < int > vc;
	for ( int i = 0; i < n; i++ ) {
		if ( i & 1 ) {
			vc.push_back( tout[i] );
		}
		else {
			vc.push_back( tin[i] );
		}
	}
	sort( vc.begin(), vc.end() );
	int x = 0;
	map < int, int > mp;
	for ( auto i: vc ) {
		mp[i] = x++;
	}
	for ( int i = 0; i < n; i++ ) {
		if ( i & 1 ) {
			lb[i] = mp[ tout[i] ];
		}
		else {
			lb[i] = mp[ tin[i] ];
		}
	}
	return lb;
}
 
int find_next_station(int s, int t, vector<int> c) {
	int sz = c.size(), pr = -1;
	int tins = -1, touts = -1;
	vector < int > tin(sz), tout(sz);
	if ( c[0] > s ) { // s is in even layer, s in tin
		tins = s;
		if ( s == 0 ) {
			touts = c.back() + 1;
		}
		else {
			touts = c[sz - 2] + 1;
			pr = c.back();
			c.pop_back();
			sz--;
		}
		tin[0] = tins;
		tout[0] = c[0];
		for ( int i = 1; i < sz; i++ ) {
			tin[i] = tout[i - 1] + 1;
			tout[i] = c[i];
		}
	}
	else { // s in odd layer
		touts = s;
		if ( sz == 1 ) {
			tins = s - 1;
			return c[0];
		}
		else {
			pr = c[0];
			c.erase(c.begin());
			sz--;
			tins = c[0] - 1;
		}
		tout[sz - 1] = s - 1;
		tin[sz - 1] = c[sz - 1];
		for ( int i = sz - 2; i >= 0; i-- ) {
			tout[i] = tin[i + 1] - 1;
			tin[i] = c[i];
		}
	}
	// cout << tins << ' ' << touts << ' ' << pr << endl;
	for ( int i = 0; i < sz; i++ ) {
		int u = c[i];
		// cout << tin[i] << " " << tout[i] << endl;
		if ( tin[i] <= t && tout[i] >= t ) {
			return u;
		}
	}
	return pr;
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:62:17: warning: variable 'touts' set but not used [-Wunused-but-set-variable]
   62 |  int tins = -1, touts = -1;
      |                 ^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 831 ms 55440 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 954 ms 1248 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 829 ms 55496 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 852 ms 548 KB Output is correct
2 Incorrect 642 ms 556 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 847 ms 55508 KB Wrong query response.
2 Halted 0 ms 0 KB -