# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
429886 | dreezy | 기지국 (IOI20_stations) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<int> labels;
vector<vector<int>> graph;
void dfs(int n,int p, int curlabel){
labels[n] = curlabel;
for(int adj : graph[n])
{
if(adj != p)
dfs(adj, n, curlabel + 1);
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> cnt(n);
labels.assign(n, 0);
graph.assign( n, vector<int>());
for (int i = 0; i < n - 1; i++) {
//cout << u[i]<<", "<<v[i]<<endl;
cnt[u[i]]++;
cnt[v[i]]++;
graph[u[i]].pb(v[i]);
graph[v[i]].pb(u[i]);
}
int root = 0;
for(int i=0; i<n; i++)
if(cnt[i] >2){
root = i;
break;
}
graph[root] = 0;
int counter = 0;
for(int branch : graph[root]){
dfs(branch, root,counter * 1000 +1);
counter++;
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
int startbranch = s/1000;
int endbranch = t/1000;
if(s == 0){
return endbranch * 1000 + 1;
}
if(startbranch == endbranch){
if(s < t)
return s + 1;
}
if( (s - 1) % 1000 == 0)
return 0;
return s -1;
}
/************/