#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> ad[1005];
int h[1005], tin[1005], tout[1005], dfsc = 0;
bool visited[1005];
void dfs(int u)
{
visited[u] = 1; tin[u] = ++dfsc;
for(int v : ad[u]) if(visited[v] == 0){h[v] = h[u] + 1; dfs(v);}
visited[u] = 0; tout[u] = ++dfsc;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n);
for(int i = 0; i <= n; i++) ad[i].clear();
for(int i = 0; i < u.size(); i++){
ad[u[i]].push_back(v[i]);
ad[v[i]].push_back(u[i]);
}
dfsc = 0; dfs(0);
for(int i = 0; i < n; i++){
if(h[i]%2 == 0) labels[i] = tin[i];
else labels[i] = tout[i];
}
vector<int> vec = labels;
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
for(int &i : labels) i = upper_bound(vec.begin(), vec.end(), i) - vec.begin();
labels[0] = 0;
//cerr<<"B"<<endl;
//for(int i : labels) cerr<<i<<" ";
//cerr<<endl;
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
sort(c.begin(), c.end());
if(s == 0){
//s is the root
for(int i : c) if(i >= t) return i;
}
else if(s < c[0]){
//s is tin, c is tout
int par;
if(c[0] == 0){
par = c[0]; c.erase(c.begin());
}
else{
par = c.back(); c.pop_back();
}
if(c.size() == 0) return par;
if(t < s || t > c.back()) return par;
for(int i : c) if(i >= t) return i;
}
else{
//s is tout, c is tin
int par = c[0]; c.erase(c.begin());
if(c.size() == 0) return par;
//cerr<<"A"<<s<<" "<<par<<" "<<t<<endl;
if(t < c[0] || t > s) return par;
int last = -1;
for(int i : c){
if(i > t) return last;
last = i;
}
return last;
}
return -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... |