#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int N=1e3+100;
const int M=2e3;
vector<int> ma[N];
int tin[N],tout[N],timer=-1;
void dfs(int v, int p)
{
tin[v] = ++timer; // n
for (auto u:ma[v]) {
if (u != p)
dfs(u, v);
}
tout[v] = ++timer; // n
}
bool is_ancestor(int u, int v)
{
int tn=u/M;
int tot=u%M;
int tn1=v/M;
int tot1=v%M;
return tn <= tn1 && tot >= tot1;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
timer=-1;
for(int i=0;i<(n);i++)ma[i].clear();
vector<int> labels(n,0);
for(int i=0;i<(n-1);i++)
{
ma[u[i]].push_back(v[i]);
ma[v[i]].push_back(u[i]);
}
dfs(0,-1);
for(int i=0;i<n;i++)
labels[i]=(tin[i]*M)+tout[i];
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(is_ancestor(s,t))
{
for(auto k:c)
{
if(is_ancestor(k,t)){
return k;
}
}
}
for(auto k:c)
if(is_ancestor(k,s))
return k;
return -1;
}
# |
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=14014 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1991 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Invalid labels (values out of range). scenario=1, k=1000000, vertex=3, label=1157149 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
654 ms |
684 KB |
Output is correct |
2 |
Incorrect |
474 ms |
684 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
375 ms |
684 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |