#include <bits/stdc++.h>
#include "stations.h"
#include <vector>
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
vector<ll> c[100005];
ll T;
ll in[100005], out[100005], pp[100005];
void dfs(int h,int p=-1)
{
pp[h]=p;
in[h]=++T;
for (int i = 0; i < c[h].size(); i++)
if (c[h][i]!=p)
{
dfs(c[h][i], h);
}
out[h]=++T;
}
bool is_ancestor(int x,int y)
{
return in[x]<=in[y] && out[x]>=out[y];
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
T=0;
for (int i = 0; i < n; i++) {
labels[i] = i;
c[i].clear();
}
for (int i = 0; i < n-1; i++)
{
c[u[i]].pb(v[i]);
c[v[i]].pb(u[i]);
}
dfs(0);
return labels;
}
ll TT;
bool dfs2(int h,int p=-1)
{
if (h==TT) return 1;
for (int i = 0; i < c[h].size(); i++)
if (c[h][i]!=p)
{
if (dfs2(c[h][i], h)) return 1;
}
return 0;
}
int find_next_station(int s, int t, std::vector<int> cc)
{
//cout << "!\n";
/*if (!is_ancestor(s, t))
{
TT=t;
assert(dfs2(pp[s], s));
return pp[s];
}
for (int i = 0; i < cc.size(); i++)
if (is_ancestor(cc[i], t) && pp[s]!=cc[i])
{
TT=t;
assert(dfs2(cc[i], s));
return cc[i];
}*/
for (int i = 0; i < cc.size(); i++)
{
TT=t;
if (dfs2(cc[i], s)) return cc[i];
}
assert(0);
}
/*
1
5 10
0 1
1 2
1 3
2 4
2
2 0 2
1 3 3
*/
Compilation message
stations.cpp: In function 'void dfs(int, int)':
stations.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < c[h].size(); i++)
| ~~^~~~~~~~~~~~~
stations.cpp: In function 'bool dfs2(int, int)':
stations.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int i = 0; i < c[h].size(); i++)
| ~~^~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:84:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for (int i = 0; i < cc.size(); i++)
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
7988 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
7832 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
7968 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
881 ms |
5264 KB |
Output is correct |
2 |
Runtime error |
7 ms |
7824 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
7996 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |