Submission #410902

# Submission time Handle Problem Language Result Execution time Memory
410902 2021-05-23T21:59:54 Z 534351 Stations (IOI20_stations) C++17
100 / 100
1160 ms 816 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;
//inside each vtx, we store start time and finish time.

void dfs(int u, int p)
{
    if (depth[u] % 2 == 0)
    {
        st[u] = T;
        ans[u] = st[u];
        T++;
    }
	for (int v : edge[u])
	{
		if (v == p) continue;
        depth[v] = depth[u] + 1;
		dfs(v, u);
	}
    if (depth[u] % 2 == 1)
    {
        ft[u] = T;
        ans[u] = ft[u];
        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.resize(N);
	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);
	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. your ft is the second largest neighbor unless you are the root, and then it's the largest + 1.
        if (u == 0)
        {
            ft = ch.back() + 1;
        }
        else
        {
            ft = (SZ(ch) > 1 ? ch[SZ(ch) - 2] : u) + 1;
        }
        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
        {
            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) //you are a leaf. then whatever.
        {
            return ch[0];
        }
        else //you have some children. the minimum guy to be considered in your subtree must be ch[0]
        {
            st = ch[0];
        }
        if (st <= v && v <= u)
        {
            //you're going to an st in your subtree
            FORD(i, SZ(ch), 0)
            {
                if (ch[i] <= v) return ch[i];
            }
        }
        else
        {
            return ch[0];
        }
    }
    assert(false);
}
# Verdict Execution time Memory Grader output
1 Correct 580 ms 504 KB Output is correct
2 Correct 586 ms 528 KB Output is correct
3 Correct 995 ms 508 KB Output is correct
4 Correct 776 ms 544 KB Output is correct
5 Correct 754 ms 528 KB Output is correct
6 Correct 534 ms 516 KB Output is correct
7 Correct 500 ms 516 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 5 ms 596 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 611 ms 512 KB Output is correct
2 Correct 618 ms 524 KB Output is correct
3 Correct 1136 ms 504 KB Output is correct
4 Correct 748 ms 516 KB Output is correct
5 Correct 774 ms 416 KB Output is correct
6 Correct 466 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 568 ms 656 KB Output is correct
2 Correct 594 ms 644 KB Output is correct
3 Correct 1099 ms 516 KB Output is correct
4 Correct 628 ms 556 KB Output is correct
5 Correct 604 ms 516 KB Output is correct
6 Correct 553 ms 528 KB Output is correct
7 Correct 609 ms 520 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 5 ms 596 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 571 ms 400 KB Output is correct
12 Correct 590 ms 748 KB Output is correct
13 Correct 492 ms 788 KB Output is correct
14 Correct 580 ms 528 KB Output is correct
15 Correct 55 ms 548 KB Output is correct
16 Correct 66 ms 684 KB Output is correct
17 Correct 107 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 913 ms 516 KB Output is correct
2 Correct 802 ms 528 KB Output is correct
3 Correct 711 ms 528 KB Output is correct
4 Correct 2 ms 712 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 669 ms 528 KB Output is correct
8 Correct 1160 ms 400 KB Output is correct
9 Correct 701 ms 632 KB Output is correct
10 Correct 685 ms 656 KB Output is correct
11 Correct 7 ms 468 KB Output is correct
12 Correct 6 ms 604 KB Output is correct
13 Correct 6 ms 596 KB Output is correct
14 Correct 4 ms 464 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 482 ms 528 KB Output is correct
17 Correct 662 ms 400 KB Output is correct
18 Correct 613 ms 512 KB Output is correct
19 Correct 599 ms 672 KB Output is correct
20 Correct 629 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 581 ms 644 KB Output is correct
2 Correct 539 ms 768 KB Output is correct
3 Correct 1136 ms 512 KB Output is correct
4 Correct 814 ms 516 KB Output is correct
5 Correct 763 ms 512 KB Output is correct
6 Correct 615 ms 536 KB Output is correct
7 Correct 444 ms 516 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 6 ms 596 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 653 ms 504 KB Output is correct
12 Correct 636 ms 520 KB Output is correct
13 Correct 1105 ms 528 KB Output is correct
14 Correct 810 ms 528 KB Output is correct
15 Correct 737 ms 512 KB Output is correct
16 Correct 530 ms 528 KB Output is correct
17 Correct 668 ms 532 KB Output is correct
18 Correct 524 ms 636 KB Output is correct
19 Correct 645 ms 660 KB Output is correct
20 Correct 595 ms 528 KB Output is correct
21 Correct 72 ms 528 KB Output is correct
22 Correct 68 ms 548 KB Output is correct
23 Correct 110 ms 660 KB Output is correct
24 Correct 7 ms 604 KB Output is correct
25 Correct 6 ms 604 KB Output is correct
26 Correct 6 ms 596 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 449 ms 516 KB Output is correct
30 Correct 455 ms 400 KB Output is correct
31 Correct 684 ms 528 KB Output is correct
32 Correct 577 ms 528 KB Output is correct
33 Correct 646 ms 516 KB Output is correct
34 Correct 345 ms 528 KB Output is correct
35 Correct 429 ms 648 KB Output is correct
36 Correct 543 ms 628 KB Output is correct
37 Correct 579 ms 516 KB Output is correct
38 Correct 446 ms 512 KB Output is correct
39 Correct 551 ms 652 KB Output is correct
40 Correct 461 ms 648 KB Output is correct
41 Correct 594 ms 516 KB Output is correct
42 Correct 82 ms 528 KB Output is correct
43 Correct 134 ms 792 KB Output is correct
44 Correct 130 ms 528 KB Output is correct
45 Correct 238 ms 624 KB Output is correct
46 Correct 382 ms 528 KB Output is correct
47 Correct 419 ms 528 KB Output is correct
48 Correct 81 ms 656 KB Output is correct
49 Correct 69 ms 816 KB Output is correct