#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] =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) {
for(int adj : c){
if(adj < s) continue;
//cout << s <<"->"<<t<<": "<<adj<<", "<<sz[adj]<<endl;
if(adj<= t and t <= adj + sz[adj] -1)
return adj;
}
return c[0];
}
/************/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
656 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
664 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
732 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
744 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |