Submission #819387

#TimeUsernameProblemLanguageResultExecution timeMemory
819387Alihan_8Stations (IOI20_stations)C++17
5 / 100
640 ms720 KiB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define pb push_back
#define ln '\n'
//#define int long long

template <class _T>
bool chmin(_T &x, const _T &y){
    bool flag = false;
    if ( x > y ){
        x = y; flag |= true;
    }
    return flag;
}

template <class _T>
bool chmax(_T &x, const _T &y){
    bool flag = false;
    if ( x < y ){
        x = y; flag |= true;
    }
    return flag;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    vector <int> g[n];
    for ( int i = 0; i + 1 < n; i++ ){
        g[u[i]].pb(v[i]);
        g[v[i]].pb(u[i]);
    }
    int r = -1;
    for ( int i = 0; i < n; i++ ){
        if ( (int)g[i].size() == 1 ){
            r = i;
        }
    }
    vector <int> ans(n), used(n);
    used[r] = true;
    while ( true ){
        int nxt = -1;
        for ( auto to: g[r] ){
            if ( !used[to] ){
                nxt = to;
            }
        }
        if ( nxt == -1 ){
            break;
        }
        ans[nxt] = ans[r] + 1;
        used[nxt] = true;
        swap(r, nxt);
    }
    return ans;
}

int find_next_station(int s, int t, vector<int> c) {
    if ( (int)c.size() == 1 ){
        return c[0];
    }
    return s < t ? c[1] : c[0];
}
#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...