#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);
}
for (int v : c){
if(v==0)continue;
if(t%(10*level) == v)
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 |
29 ms |
844 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 |
12 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 |
669 ms |
684 KB |
Output is correct |
2 |
Correct |
472 ms |
684 KB |
Output is correct |
3 |
Correct |
435 ms |
684 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Incorrect |
3 ms |
768 KB |
Wrong query response. |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
668 KB |
Invalid labels (values out of range). scenario=1, k=1000000000, vertex=0, label=1111111112 |
2 |
Halted |
0 ms |
0 KB |
- |