#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<int> labels;
vector<vector<int>> graph;
void dfs(int n,int p, int curlabel){
labels[n] = curlabel;
for(int adj : graph[n])
{
if(adj != p)
dfs(adj, n, curlabel + 1);
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> cnt(n);
labels.assign(n, 0);
graph.assign( n, vector<int>());
for (int i = 0; i < n - 1; i++) {
//cout << u[i]<<", "<<v[i]<<endl;
cnt[u[i]]++;
cnt[v[i]]++;
graph[u[i]].pb(v[i]);
graph[v[i]].pb(u[i]);
}
int root = 0;
for(int i=0; i<n; i++)
if(cnt[i] >2){
root = i;
break;
}
labels[root] = 0;
int counter = 0;
for(int branch : graph[root]){
dfs(branch, root,counter * 1000 +1);
counter++;
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
int startbranch = s/1000;
int endbranch = t/1000;
if(s == 0){
return t;
}
if(startbranch == endbranch){
if(s < t)
return s + 1;
}
if( (s - 1) % 1000 == 0)
return 0;
return s -1;
}
/************/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
416 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1005 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
292 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=3, label=1001 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
515 ms |
656 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
923 ms |
400 KB |
Output is correct |
2 |
Incorrect |
672 ms |
400 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
569 ms |
604 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |