Submission #930143

#TimeUsernameProblemLanguageResultExecution timeMemory
930143quanlt206Stations (IOI20_stations)C++17
100 / 100
580 ms1764 KiB
#include<bits/stdc++.h>
#define X first
#define Y second
#define all(x) begin(x), end(x)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, b, a) for(int i = (b); i >= (a); i--)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define mxx max_element
#define mnn min_element
#define SQR(x) (1LL * (x) * (x))
#define MASK(i) (1LL << (i))
#define Point Vector
#define left Left
#define right Right
#define div Div

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef pair<ll, int> pli;
typedef pair<ll, pii> plii;

template<class A, class B>
    bool maximize(A& x, B y) {
        if (x < y) return x = y, true; else return false;
    }
template<class A, class B>
    bool minimize(A& x, B y) {
        if (x > y) return x = y, true; else return false;
    }
/* END OF TEMPLATE */

const int N = 3e3 + 7;

vector<int> v[N];

int st[N], ed[N], cnt = 0, high[N];
int lab[N];

void compress_label(int n) {
    vector<int> E;
    REP(i, 0, n) E.push_back(lab[i]);
    sort(all(E));
    REP(i, 0, n) lab[i] = lower_bound(all(E), lab[i]) - E.begin();
}

void dfs(int x, int par) {
    st[x] = ++cnt;
    for (auto y : v[x])
        if (y != par) {
            high[y] = high[x] + 1;
            dfs(y, x);
        }
    ed[x] = ++cnt;
}

vector<int> label(int n, int k, vector<int> a, vector<int> b) {
    REP(i, 0, n) v[i].clear();
    REP(i, 0, n - 1) {
        v[a[i]].push_back(b[i]);
        v[b[i]].push_back(a[i]);
    }
    cnt = 0;
    dfs(0, 0);
//    REP(i, 0, n) cout<<st[i]<<" "<<ed[i]<<"\n";
    REP(i, 0, n)
        if (high[i] % 2 == 0) lab[i] = st[i]; else lab[i] = ed[i];
    compress_label(n);
    vector<int> res(lab, lab + n);
//    for (auto x : res) cout<<x<<" "; cout<<"\n";
    return res;
}

int find_next_station(int s, int t, vector<int> c) {
    sort(all(c));
    if (binary_search(all(c), t)) return t;
    int n = c.size();
    if (s < c[0]) {
        // s thoi diem vao
        if (s != 0) {
            // check xem t co nam ngoai cay con goc s hay khong
            if (n == 1 || t < s || t > c[n - 2]) return c[n - 1]; // return cha
        }
        for (auto x : c)
            if (x > t) return x;
    }
    // s thoi diem ra
    if (s != 0) {
        if (n == 1 || t > s || t < c[1]) return c[0];
    }
    int res = 0;
    for (auto x : c)
        if (x <= t) res = x;
    return res;
}
#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...