#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
#define pb push_back
vector<vector<int>> adj;
vector <int> in;
vector <int> out;
int cnt = -1;
void dfs (int node, int last)
{
cnt++;
in[node] = cnt;
for (int next : adj[node])
{
if (next==last)
{
continue;
}
dfs(next, node);
}
out[node] = cnt;
}
bool check(int lab1, int lab2)
{
int cur_in = lab1/1000;
int cur_out = lab1%1000;
int des_in = lab2/1000;
int des_out = lab2%1000;
if (cur_in < des_in and des_in <= cur_out)
{
return true;
}
else
{
return false;
}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v)
{
in.resize(n+1);
out.resize(n+1);
adj.resize(n+1);
vector <int> labels;
for (int i = 0; i < n-1; i++)
{
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
dfs(0, -1);
for (int i=0; i<n; i++)
{
labels.pb(in[i]*1000 + out[i]);
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c)
{
if (check(s, t))
{
for (int child : c)
{
if (child==t)
{
return child;
}
if (check(child, s))
{
continue;
}
if (check(child, t))
{
return child;
}
}
}
else
{
for (int child : c)
{
if (child==t)
{
return child;
}
if (check(child, s))
{
return child;
}
}
}
return c[0];
}
Compilation message
stations.cpp: In function 'bool check(int, int)':
stations.cpp:32:9: warning: unused variable 'des_out' [-Wunused-variable]
32 | int des_out = lab2%1000;
| ^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
408 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3055 ms |
5720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1679 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1031 ms |
472 KB |
Output is correct |
2 |
Runtime error |
1271 ms |
2097156 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3096 ms |
2097156 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |