#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4+3;
vector<int> adj[MAXN];
int tin[MAXN], tout[MAXN], tempo;
bool used[MAXN];
void dfs(int no){
used[no] = true;
tin[no] = ++tempo;
for(int v : adj[no]) if(!used[v]){
dfs(v);
}
tout[no] = tempo;
}
inline int pre(int a);
inline int pos(int a);
vector<int> label(int n, int k, vector<int> u, vector<int> v){
for(int i = 0; i < n; i++){
used[i] = false;
tin[i] = tout[i] = 0;
adj[i].clear();
}
tempo = 0;
for (int i = 0; i < (int)u.size(); i++){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
int ponta = 0;
for(int i = 0; i < n; i++) if(adj[i].size() == 1) ponta = i;
dfs(ponta);
vector<int> labels(n);
for (int i = 0; i < n; i++) {
labels[i] = tin[i];
// labels[i] = tin[i]*10000+tout[i];
// cerr << "i: " << i << " " << pre(labels[i]) << ' ' << pos(labels[i]) << endl;
}
return labels;
}
inline int pre(int a){
return a/10000;
}
inline int pos(int a){
return a%10000;
}
int find_next_station(int s, int t, vector<int> c) {
// if(pre(s) <= pre(t) && pos(t) <= pos(s)){ //t eh filho
// for(int l : c){
// if(pre(l) <= pre(s) && pos(s) <= pos(l)) continue;
// if(pre(l) <= pre(t) && pos(t) <= pos(l)) return l;
// }
// }
// for(int l : c){
// if(pre(l) <= pre(s) && pos(s) <= pos(l)) return l;
// }
if(t < s) return min(c[0], c[1]);
else return max(c[0], c[1]);
}
| # | 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... |