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"
#include <vector>
using namespace std;
const int N = 1000;
int T;
vector<int> adj[N], lb(N);
void dfs(int s){
if(lb[s]!=-1) return;
lb[s] = (T/2)*N; T++;
for(auto u : adj[s]) dfs(u);
lb[s] += (T/2); T++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for(int i=0; i<N; ++i) adj[i].clear();
lb.resize(N);
fill(lb.begin(), lb.end(), -1);
T = 0;
for(int i=0; i<n-1; ++i){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0);
lb.resize(n);
return lb;
}
int find_next_station(int s, int t, vector<int> c) {
// x entrata, y uscita
int x1 = s/N; int y1 = s%N;
int x2 = t/N; int y2 = t%N;
int par = s; //parent di s
for(auto u : c){
int x3 = u/N; int y3 = u%N;
if(x3 <= x1 && y1 <= y3) par = u;
}
//cout << par;
if(x1 <= x2 && y2 <= y1){ // s é parent di t
for(auto u : c){
int x3 = u/N; int y3 = u%N;
if(x3 <= x2 && y2 <= y3 && u != par) return u; //parent di t più in basso di s
}
}
return par;
}
# | 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... |