이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
int cnt;
vector<vector<int>> g;
vector<int> in, out, d;
void dfs(int cur, int dep){
if (d[cur] != -1) return;
d[cur] = dep;
in[cur] = cnt++;
for (int next : g[cur]) dfs(next, dep+1);
out[cur] = cnt++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
g.resize(n);
for (int i=0; i<n-1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
in.resize(n); out.resize(n); d.resize(n, -1);
cnt = 0;
dfs(0, 0);
vector<int> l(n);
for (int i=0; i<n; i++){
if (d[i] % 2) l[i] = out[i];
else l[i] = in[i];
}
vector<int> w = l;
sort(w.begin(), w.end());
unordered_map<int,int> m;
for (int i=0; i<n; i++) m[w[i]] = i;
for (int i=0; i<n; i++) l[i] = m[l[i]];
return l;
}
int find_next_station(int s, int t, vector<int> c){
if (c.size() == 0) return c[0];
if (s == 0){
vector<int> d(c.size());
for (int i=0; i<c.size(); i++){
if (i == 0) d[i] = s+1;
else d[i] = c[i-1]+1;
if (d[i] <= t && t <= c[i]) return c[i];
}
}
else {
int x = 2000;
for (int y : c) x = min(x, y);
if (s < x){
vector<int> d(c.size()-1);
for (int i=0; i<c.size()-1; i++){
if (i == 0) d[i] = s+1;
else d[i] = c[i-1]+1;
if (d[i] <= t && t <= c[i]) return c[i];
}
return c.back();
}
else {
vector<int> d(c.size());
for (int i=c.size()-1; i>=0; i--){
if (i == c.size()-1) d[i] = s-1;
else d[i] = c[i+1]-1;
if (c[i] <= t && t <= d[i]) return c[i];
}
return c[0];
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i=0; i<c.size(); i++){
| ~^~~~~~~~~
stations.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i=0; i<c.size()-1; i++){
| ~^~~~~~~~~~~
stations.cpp:64:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | if (i == c.size()-1) d[i] = s-1;
| ~~^~~~~~~~~~~~~
stations.cpp:71:1: warning: control reaches end of non-void function [-Wreturn-type]
71 | }
| ^
# | 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... |