답안 #410895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410895 2021-05-23T21:47:41 Z 534351 기지국 (IOI20_stations) C++17
0 / 100
1047 ms 908 KB
#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;
const int INF = 1e9 + 7;

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], depth[MAXN];
vi ans, compress;
//inside each vtx, we store start time and finish time.

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

vi label(int n, int k, vi U, vi V)
{
	N = n; K = k; T = 0;
	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);
	}
    depth[0] = 0;
	dfs(0, N);
	ans.resize(N);
    FOR(i, 0, N)
    {
        if (depth[i] % 2)
        {
            ans[i] = ft[i];
        }
        else
        {
            ans[i] = st[i];
        }
    }
    compress = ans;
    sort(ALL(compress));
    FOR(i, 0, N)
    {
        ans[i] = LB(ALL(compress), ans[i]) - compress.begin();
    }
	return ans;
}

int find_next_station(int u, int v, vi ch)
{
    sort(ALL(ch));
    //figure out if you're a st or ft.
    //case 1: you're an st. then any neighbor will have ft > u.
    if (u < ch[0])
    {
        int ft = -1;
        //you're an st.
        if (u == 0)
        {
            //you are the root. your finishing time is w/e.
            ft = ch.back();
        }
        else
        {
            //your ft is the second largest neighbor
            ft = (SZ(ch) > 1 ? ch[SZ(ch) - 2] : u);
        }
        if (u <= v && v <= ft)
        {
            //you're going to an ft, which still is >= v.
            FOR(i, 0, SZ(ch))
            {
                if (ch[i] >= v) return ch[i];
            }
        }
        else //you go to your parent.
        {
            return ch.back();
        }
    }
    else
    {
        //you're an ft. your st is the smallest child - 1, unless you only have a parent.
        int st = -1;
        if (SZ(ch) == 1)
        {
            st = ch[0] + 1;
        }
        else
        {
            st = ch[0] - 1;
        }
        if (st <= v && v <= u)
        {
            //you're going to an st, which is <= v.
            FORD(i, SZ(ch), 0)
            {
                if (ch[i] <= v) return ch[i];
            }
        }
        else
        {
            return ch[0];
        }
    }
    assert(false);
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 908 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 75 ms 764 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 900 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1047 ms 400 KB Output is correct
2 Correct 702 ms 528 KB Output is correct
3 Correct 737 ms 512 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Runtime error 2 ms 852 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 16 ms 884 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -