#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 = 0;
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) {
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 |
Incorrect |
3 ms |
328 KB |
Invalid labels (values out of range). scenario=2, k=1000, vertex=69, label=1001 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
412 KB |
Invalid labels (values out of range). scenario=1, k=1000, vertex=2, label=1508 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
740 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
528 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
784 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |