#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{
//if( t > s) return c[0];
//reverse(c.begin(), c.end());
for(int adj : c)
if(t <= adj)
return adj;
return c[0];
}
return c[0];
}
/************/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
328 KB |
Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1990 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
388 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1022 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
592 ms |
676 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
865 ms |
524 KB |
Output is correct |
2 |
Correct |
690 ms |
400 KB |
Output is correct |
3 |
Incorrect |
657 ms |
484 KB |
Wrong query response. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
554 ms |
520 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |