이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
vector<vector<int>> g(n);
for(int i=0; i+1<n; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
vector<int> l(n);
int t = 0;
function<void(int, int, int)> dfs = [&](int u, int d, int p){
if(d%2==0){
l[u]=t++;
}
for(int v:g[u]){
if(v==p){
continue;
}
dfs(v, d+1, u);
}
if(d%2==1){
l[u]=t++;
}
};
dfs(0, 0, -1);
return l;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(c.size()==1){
return c[0];
}
if(c.back()<s){
// saved time is tout
// check if we hold it
int tin = c[0], tout = s;
if(not (tin <= t and t < tout)){
return c[0];
}
for(int i=1; i<c.size(); i++){
tin = c[i], tout = (i+1 < c.size() ? c[i+1] : s);
if(tin <= t and t < tout){
return c[i];
}
}
// we hold it if tin <= t < tout or s == 0
// if not go to par
}else{
int tin = s, tout = c[c.size()-2];
if(not (tin < t and t <= tout)){
return c.back();
}
if(s!=0){
c.pop_back();
}
for(int i=0; i<c.size(); i++){
tin = (i-1>=0 ? c[i-1] : s), tout = c[i];
if(tin < t and t<= tout){
return c[i];
}
}
}
assert(false);
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:44:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=1; i<c.size(); i++){
| ~^~~~~~~~~
stations.cpp:45:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | tin = c[i], tout = (i+1 < c.size() ? c[i+1] : s);
| ~~~~^~~~~~~~~~
stations.cpp:60:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i=0; i<c.size(); i++){
| ~^~~~~~~~~
# | 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... |