This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 vis[1001];
int cnt = -1;
void dfs (int node)
{
cnt++;
in[node] = cnt;
vis[node] = true;
for (int next : adj[node])
{
if (!vis[next])
{
dfs(next);
}
}
out[node] = cnt;
return ;
}
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);
memset (vis,0,sizeof(vis));
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);
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];
}
/*
1
5 10000000
0 1
1 2
1 3
2 4
2
2 0 1
1 3 3
*/
Compilation message (stderr)
stations.cpp: In function 'bool check(int, int)':
stations.cpp:34:9: warning: unused variable 'des_out' [-Wunused-variable]
34 | int des_out = lab2%1000;
| ^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |