Submission #410516

#TimeUsernameProblemLanguageResultExecution timeMemory
410516534351Stations (IOI20_stations)C++17
10 / 100
1004 ms900 KiB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()

const int MAXN = 1013;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N, K, T;
vi edge[MAXN];
int st[MAXN], ft[MAXN];
vi ans;
//inside each vtx, we store start time and finish time.

void dfs(int u, int p)
{
	st[u] = T;
	ft[u] = T;
	T++;
	for (int v : edge[u])
	{
		if (v == p) continue;
		dfs(v, u);
		ft[u] = ft[v];
	}
}

vi label(int n, int k, vi U, vi V)
{
	N = n; K = k;
	FOR(i, 0, N)
	{
		edge[i].clear();
	}
	ans.clear();
	FOR(i, 0, N - 1)
	{
		int u = U[i], v = V[i];
		edge[u].PB(v);
		edge[v].PB(u);
	}
	dfs(0, N);
	ans.resize(N);
	FOR(i, 0, N)
	{
		ans[i] = st[i] * 1000 + ft[i];
	}
	return ans;
}

int find_next_station(int s, int t, vi ch)
{
	//you're at s and you want to go to t.
	int stu = s / 1000, ftu = s % 1000;
	int stv = t / 1000, ftv = t % 1000;
	if (stu <= stv && stv <= ftu)
	{
		for (int x : ch)
		{
			int stx = x / 1000, ftx = x % 1000;
			if (stx < stu) continue;
			if (stx <= stv && stv <= ftx)
			{
				return x;
			}
		}
	}
	for (int x : ch)
	{
		int stx = x / 1000, ftx = x % 1000;
		if (stx < stu) return x;
	}
	assert(false);
}

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, vi)':
stations.cpp:101:23: warning: unused variable 'ftx' [-Wunused-variable]
  101 |   int stx = x / 1000, ftx = x % 1000;
      |                       ^~~
stations.cpp:86:22: warning: unused variable 'ftv' [-Wunused-variable]
   86 |  int stv = t / 1000, ftv = t % 1000;
      |                      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...