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 <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<int> labels;
vector<vector<int>> graph;
vector<int> sz;
void dfs1(int n,int p){//calc sizes
sz[n] = 1;
for(int adj : graph[n])
{
if(adj == p) continue;
dfs1(adj, n);
sz[n] += sz[adj];
}
}
int counter;
void name_subtree(int n, int p){
labels[n] =sz[n] + (counter << 10) ;
counter++;
for(int adj : graph[n]){
if(adj == p)
continue;
name_subtree(adj, n);
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
counter = 0;
sz.clear();
labels.clear();
graph.clear();
sz.assign(n, 0);
labels.assign(n, 0);
graph.assign( n, vector<int>());
for (int i = 0; i < n - 1; i++) {
graph[u[i]].pb(v[i]);
graph[v[i]].pb(u[i]);
}
int root = 0;
dfs1(0,-1);
//for(int i =0; i<n; i++) cout <<i<<": "<< sz[i]<<endl;
name_subtree(root, -1);
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
int startind = ( s>> 10);
int targetind = (t>>10);
for(int adj : c){
int adjind = (adj >> 10);
if(adjind < startind) continue;
//cout << s <<"->"<<t<<": "<<adj<<", "<<sz[adj]<<endl;
if(adjind<= targetind and targetind <= adjind + adj - (adjind<<10) -1){
//cout << startind<<"->"<<targetind<<": "<<adjind<<", "<<adj - (adjind<<10) -1 <<endl;
return adj;
}
}
return c[0];
}
/************/
# | 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... |