This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 0;
for ( int i = 0; i < n; i++ ){
if ( (int)g[i].size() > 2 ){
r = i;
}
}
vector <int> ans(n, -1);
ans[r] = 0;
auto &a = g[r];
for ( int i = 0; i < (int)a.size(); i++ ){
function <void(int,int)> dfs = [&](int x, int depth){
ans[x] = depth + i * 1000;
for ( auto to: g[x] ){
if ( ans[to] != -1 ){
continue;
}
dfs(to, depth + 1);
}
}; dfs(a[i], 1);
}
return ans;
}
int find_next_station(int s, int t, vector<int> c) {
const int f = 1e3;
if ( !s ) return t / f * f + 1;
if ( (s + f - 1) / f != (t + f - 1) / f ){
return (s - 1) % f ? s - 1 : 0;
}
return s < t ? s + 1 : !(s - 1 % f) ? 0 : s - 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |