#include "stations.h"
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
vector<vector<int>> paths(1001);
vector<int> dist(1001,-1);
void dfs(int pos,int len){
if(dist[pos] != -1)return;
dist[pos] = len;
for(int i:paths[pos])dfs(i,len+1);
}
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 = 0;
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*1000);
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];
for (int v : c)
if (v == t)
return t;
if((t/1000) != (s/1000))return c[0];
if(t>s)return c[1];
return c[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=2004 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
344 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1007 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
362 ms |
684 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
623 ms |
684 KB |
Output is correct |
2 |
Correct |
450 ms |
684 KB |
Output is correct |
3 |
Incorrect |
399 ms |
944 KB |
Wrong query response. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
386 ms |
684 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |