Submission #419471

# Submission time Handle Problem Language Result Execution time Memory
419471 2021-06-07T07:33:38 Z vkgainz Stations (IOI20_stations) C++17
0 / 100
1043 ms 776 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> st, en, d;
vector<vector<int>> adj;
int t;
void dfs(int curr, int par) {
    st[curr] = t++;
    for(int next : adj[curr]) {
        if(next == par) continue;
        d[next] = d[curr] + 1;
        dfs(next, curr);
    }
    en[curr] = t++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    adj.clear(), st.clear(), en.clear(), d.clear();
    adj.resize(n);
    st.resize(n);
    en.resize(n);
    d.resize(n);
    for(int i = 0; i < n - 1; i++) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    vector<int> ans(n);
    t = 0;
    dfs(0, -1);
    for(int i = 0; i < n; i++) {
        if(d[i] % 2 == 0) ans[i] = st[i] / 2;
        else ans[i] = en[i] / 2;
    }
    return ans;
}

int find_next_station(int s, int t, vector<int> c) {
    bool odd = false;
    s *= 2;
    t *= 2;
    for(int i = 0; i < (int) c.size(); i++) {
        c[i] *= 2;
    }
    if(c[0] < s) odd = true;
    if(c.size() == 1) return c[0] / 2;
    if(odd) {
        for(int i = (int) c.size() - 1; i >= 1; i--) {
            if(t >= c[i] && t <= s) return c[i] / 2;
        }
        return c[0] / 2;
    }
    else {
        for(int i = 0; i < (int) c.size() - 1; i++) {
            if(t <= c[i] && t >= s) return c[i] / 2;
        }
        return c[0] / 2;
    }
    return -1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 663 ms 612 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 539 ms 488 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 596 ms 656 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1043 ms 520 KB Output is correct
2 Incorrect 767 ms 400 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 676 ms 776 KB Wrong query response.
2 Halted 0 ms 0 KB -