#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pi pair<int,int>
vector<int> labels;
vector<vector<int>> graph;
vector<pi> ord;
int cnt = 0;
void dfs1(int n,int p){//calc sizes
ord[n].first = cnt++;
for(int adj : graph[n])
{
if(adj == p) continue;
dfs1(adj, n);
}
ord[n].second = cnt++;
}
void name_subtree(int n, int p, bool first){
if(first)
labels[n] = ord[n].first;
else
labels[n] = ord[n].second;
for(int adj : graph[n]){
if(adj == p)
continue;
name_subtree(adj, n, !first);
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
cnt = 0;
ord.clear();
labels.clear();
graph.clear();
ord.assign(n, {0,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]);
}
dfs1(0,-1);
int root = 0;
//for(int i =0; i<n; i++) cout <<i<<": "<< ord[i].first<<", "<<ord[i].second<<endl;
name_subtree(root, -1, 1);
for(int i =0; i<n; i++) cout <<i<<": "<< labels[i]<<endl;
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if(c.size() == 1) return c[0];
bool isfirst = c[0] > s;
if(isfirst){
if(t < s) return c[c.size() - 1];
for(int adj : c){
if(t <= adj) return adj;
}
return c[c.size()-1] ;
}
else{
reverse(c.begin(), c.end());
if( t > s) return c[c.size()-1];
for(int adj : c)
if(t >= adj)
return adj;
return c[c.size()-1];
}
}
/************/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
200 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
272 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
304 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
268 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
292 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |