| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1292793 | lucasdmy | Stations (IOI20_stations) | C++20 | 0 ms | 0 KiB |
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1010;
vector<int>graph[MAXN], labels, sub_size(MAXN), inv(MAXN);
int c=0;
void dfs(int x, int p){
labels[x]=c;
inv[c]=x;
c++;
sub_size[x]=0;
for(int k=0;k<graph[x].size();k++){
if(graph[x][k]!=p){
dfs(graph[x][k], x);
sub_size[x]+=1+sub_size[graph[x][k]];
}
}
}
vector<int>lable(int n, int m, vector<int>a, vector<int>b){
for(int k=0;k<n;k++){
graph[k].clear();
}
labels.resize(n);
for(int k=0;k<n-1;k++){
graph[a[k]].push_back(b[k]);
graph[b[k]].push_back(a[k]);
}
c=0;
dfs(0, 0);
return labels;
}
int find_next_station(int at, int end, vector<int>adj){
if(end<at or at+sub_size[inv[at]]<end){
return adj[0];
}
for(int k=adj.size()-1;k>0;k--){
if(end>=adj[k]){
return adj[k];
}
}
return INT_MAX;
}
