이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
vector<int> label(int n, int k, vector<int> u, vector<int> v){
int timer = 0, tin[n], tout[n], dep[n];
vector<vector<int>> g(n);
for(int i = 0; i < n-1; ++i) g[u[i]].pb(v[i]), g[v[i]].pb(u[i]);
function<void(int, int)> dfs = [&](int v, int p){
tin[v] = timer++;
dep[v] = dep[p] + 1;
for(int u: g[v]){
if(u != p) dfs(u, v);
}
tout[v] = timer++;
};
dep[0] = 0;
dfs(0, 0);
vector<int> l;
for(int i = 0; i < n; ++i) l.pb(dep[i] % 2 == 1 ? tin[i] : tout[i]);
vector<int> a = l;
sort(a.begin(), a.end());
for(int i = 0; i < n; ++i) l[i] = lower_bound(a.begin(), a.end(), l[i]) - a.begin();
return l;
}
int find_next_station(int s, int t, vector<int> c){
for(int p: c){
if(p==t) return t;
}
if(s == 0){
for(int i = 0; i < c.size(); ++i){
if(c[i] >= t){
return c[i];
}
}
assert(0);
}
if(s <= c[0]){
int par = c.back();
if(t <= s || par <= t)
return par;
for(int i = 0; i < c.size() - 1; ++i){
if(c[i] >= t){
return c[i];
}
}
}
int par = c[0];
if(t >= s || t <= par){
return par;
}
for(int i = c.size() - 1; i >= 1; --i){
if(c[i] <= t){
return c[i];
}
}
return -1;
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i = 0; i < c.size(); ++i){
| ~~^~~~~~~~~~
stations.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0; i < c.size() - 1; ++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... |