#include "stations.h"
#include <vector>
#include <iostream>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
int find_leaf(int current_node, int current_node_father, vvi& G){
vector<int> adjacents;
for(int v : G[current_node]){
if(v == current_node_father) continue;
adjacents.push_back(v);
}
if(adjacents.empty()) return current_node;
return find_leaf(adjacents[0], current_node, G);
}
void find_order(int& current_id, int current_node, int current_node_father, vvi& G, vi& labels){
labels[current_node] = current_id;
current_id++;
for(int v : G[current_node]){
if(v == current_node_father) continue;
find_order(current_id, v, current_node, G, labels);
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vi labels(n);
vvi G(n);
int id=0, root = 0;
for(int i=0; i<n-1; i++){
G[u[i]].push_back(v[i]);
G[v[i]].push_back(u[i]);
}
find_order(id, find_leaf(root, -1, G), -1, G, labels);
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if((int)c.size() == 1) return c[0];
if(s > t) return c[0];
return c[1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
619 ms |
656 KB |
Output is correct |
2 |
Correct |
577 ms |
656 KB |
Output is correct |
3 |
Correct |
1124 ms |
400 KB |
Output is correct |
4 |
Correct |
677 ms |
488 KB |
Output is correct |
5 |
Correct |
683 ms |
484 KB |
Output is correct |
6 |
Correct |
584 ms |
684 KB |
Output is correct |
7 |
Correct |
598 ms |
620 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
476 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
554 ms |
484 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
595 ms |
740 KB |
Output is correct |
2 |
Correct |
446 ms |
608 KB |
Output is correct |
3 |
Correct |
1071 ms |
400 KB |
Output is correct |
4 |
Correct |
694 ms |
400 KB |
Output is correct |
5 |
Correct |
725 ms |
400 KB |
Output is correct |
6 |
Correct |
578 ms |
720 KB |
Output is correct |
7 |
Correct |
564 ms |
616 KB |
Output is correct |
8 |
Correct |
3 ms |
476 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Incorrect |
601 ms |
488 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1123 ms |
484 KB |
Output is correct |
2 |
Correct |
838 ms |
488 KB |
Output is correct |
3 |
Correct |
740 ms |
400 KB |
Output is correct |
4 |
Correct |
2 ms |
464 KB |
Output is correct |
5 |
Correct |
3 ms |
476 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Incorrect |
686 ms |
484 KB |
Wrong query response. |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
669 ms |
656 KB |
Output is correct |
2 |
Correct |
458 ms |
648 KB |
Output is correct |
3 |
Correct |
1119 ms |
528 KB |
Output is correct |
4 |
Correct |
696 ms |
400 KB |
Output is correct |
5 |
Correct |
686 ms |
404 KB |
Output is correct |
6 |
Correct |
558 ms |
656 KB |
Output is correct |
7 |
Correct |
447 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Incorrect |
598 ms |
528 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |