#include"stations.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=1010;
vector<int>v[maxn], resp;
int tmp;
void dfs(int u, int pai, int prof){
if(!prof) resp[u]=tmp++;
for(int viz : v[u]) if(viz!=pai) dfs(viz,u,1^prof);
if(prof) resp[u]=tmp++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> w){
tmp=0;
resp.clear();
for(int i=0;i<n;i++){
v[i].clear();
resp.push_back(0);
}
for(int i=0;i<n-1;i++){
v[u[i]].push_back(w[i]);
v[w[i]].push_back(u[i]);
}
dfs(0,0,0);
return resp;
}
int find_next_station(int s, int t, vector<int>adj){
if(adj.size()==1) return adj[0]; // so tem um vizinho msm, dps n vai dar rte
if(s<adj[0]){ // sou o tin e os vizinhos sao o tout
if(s>t) return adj.back(); // o tin/tout dele eh menor q o tin, ent esta fora da subtree
// se n esta na subtree
for(int i=0;i<adj.size()-1;i++) if(adj[i]>t) return adj[i]; // pego o primeiro com o tout maior do q a encomenda
}else{ // sou o tout e os vizinhos sao o tin
if(s<t) return adj[0]; // o tin/tout dele eh maior q o tout, ent esta fora da subtree
// se n esta na subtree
adj.push_back(maxn);
} for(int i=1;i<adj.size();i++) if(adj[i]>t) return adj[i-1]; // pego o cara com o tin menor, e o proximo com tin maior
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:37:1: warning: control reaches end of non-void function [-Wreturn-type]
37 | }
| ^| # | 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... |