#include "stations.h"
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
vector<vector<int>> paths(1001);
vector<int> dist(1001,-1);
void dfs(int pos,int len,int level){
if(dist[pos] != -1)return;
dist[pos] = len;
int cnt = 1;
for(int i:paths[pos]){
if(dist[i] != -1)continue;
dfs(i,len+(cnt*int(pow(10,level))),level+1);
cnt ++;
}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
paths = vector<vector<int>>(1001);
dist = vector<int>(1001,-1);
for(int i = 0;i<n-1;i++){
paths[u[i]].push_back(v[i]);
paths[v[i]].push_back(u[i]);
}
int head = 1;
// for (int i = 0; i < n; i++) {
// if(paths[i].size() > 2){
// head = i;
// }
// }
dist[head] = 0;
int cnt = 1;
for(int i:paths[head]){
dfs(i,cnt,1);
cnt ++;
}
cerr << head << endl;
for (int i = 0; i < n; i++) {
labels[i] = dist[i];
cerr << labels[i] << " ";
}
cerr << endl;
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
sort(c.begin(),c.end());
if (c.size() == 1) return c[0];
if(s == 0){
for (int v : c){
if (v%10 == t%10)
return v;
}
}
for (int v : c)
if (v == t)
return t;
if(s<t){
int level = 0;
for (int v : c){
if(v==0)continue;
int cur = 0;
while(v>0){
cur ++;
v/=10;
}
level = max(level,cur);
}
cerr << "DEBUG " << s << " " << t << " " << level << " " << t%int(pow(10,level)) << " | ";
for (int v : c){
if(v==0)continue;
cerr << v << " ";
if(t%int(pow(10,level)) == v){
cerr << endl;
return v;
}
}
}
return c[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
596 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=11111 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
588 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=11, label=1111 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
596 KB |
Invalid labels (values out of range). scenario=1, k=1000000, vertex=0, label=-1036372537 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
654 ms |
684 KB |
Output is correct |
2 |
Correct |
460 ms |
684 KB |
Output is correct |
3 |
Correct |
479 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
776 KB |
Output is correct |
7 |
Correct |
427 ms |
828 KB |
Output is correct |
8 |
Correct |
601 ms |
684 KB |
Output is correct |
9 |
Correct |
457 ms |
684 KB |
Output is correct |
10 |
Correct |
470 ms |
1108 KB |
Output is correct |
11 |
Correct |
4 ms |
764 KB |
Output is correct |
12 |
Correct |
4 ms |
776 KB |
Output is correct |
13 |
Correct |
3 ms |
768 KB |
Output is correct |
14 |
Correct |
3 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
768 KB |
Output is correct |
16 |
Correct |
448 ms |
1828 KB |
Output is correct |
17 |
Correct |
422 ms |
1628 KB |
Output is correct |
18 |
Correct |
488 ms |
1324 KB |
Output is correct |
19 |
Correct |
463 ms |
1336 KB |
Output is correct |
20 |
Correct |
469 ms |
1840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
684 KB |
Invalid labels (values out of range). scenario=1, k=1000000000, vertex=0, label=1111111112 |
2 |
Halted |
0 ms |
0 KB |
- |