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 "stations.h"
#include <iostream>
#include <vector>
#define ll int
#define ff first
#define ss second
#define ln "\n"
#define pll pair<ll, ll>
using namespace std;
vector<vector<ll>> A;
void dfs(ll u, ll p, vector<ll> &labels){
ll add=0;
for (auto v:A[u]){
if (v==p) continue;
labels[v]=(labels[u]<<1ll)+add;
add++;
dfs(v, u, labels);
}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
A.clear();
A.resize(n);
for (ll i=0; i<n-1; i++){
A[u[i]].push_back(v[i]);
A[v[i]].push_back(u[i]);
}
vector<int> labels(n);
labels[0]=1;
dfs(0, 0, labels);
// for (ll i=0; i<n; i++){
// cout << labels[i] << ln;
// }
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
ll n = (int)c.size();
ll ret=0;
ll cnts=0, cntt=0;
for (ll i=0; i<=10; i++){
if ((1ull<<i)&s){
cnts=i;
}
if ((1ull<<i)&t){
cntt=i;
}
}
if (cnts>cntt){
return c[0];
}else{
if ((t&(s<<(cntt-cnts)))==s){
if ((t&(1ll<<(cntt-cnts-1)))){
return c[c.size()-1];
}else{
return c[c.size()-2];
}
}else{
return c[0];
}
}
return ret;
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:43:5: warning: unused variable 'n' [-Wunused-variable]
43 | ll n = (int)c.size();
| ^
# | 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... |