이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1004;
vector<int> G[MAX], ans;
int in[MAX], out[MAX], dn;
void DFS(int cur, int prev, int H) {
in[cur] = dn++;
for (int next : G[cur]) {
if (next == prev) continue;
DFS(next, cur, H + 1);
}
out[cur] = dn++;
ans[cur] = ((H & 1) ? out[cur] : in[cur]);
}
vector<int> label(int N, int K, vector<int> U, vector<int> V) {
for (int i = 0; i < N - 1; ++i) {
G[U[i]].push_back(V[i]);
G[V[i]].push_back(U[i]);
}
ans.resize(N);
DFS(0, -1, 0);
vector<int> T;
for (int n : ans) T.push_back(n);
sort(T.begin(), T.end());
for (int& n : ans) n = lower_bound(T.begin(), T.end(), n) - T.begin();
for (int i = 0; i < N; ++i) G[i].clear();
dn = 0;
return ans;
}
int find_next_station(int S, int T, vector<int> C) {
if (S == T) exit(1);
sort(C.begin(), C.end());
// S is in, C is out
if (S < C[0]) {
int pv = S;
for (int i = 0; i + 1 < C.size(); ++i) {
if (pv <= T && T < C[i]) return C[i];
pv = C[i];
}
return C.back();
}
// S is out, C is in
else {
C.push_back(S);
for (int i = 1; i + 1 < C.size(); ++i) {
if (C[i] <= T && T < C[i + 1]) return C[i];
}
return C[0];
}
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:42:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 0; i + 1 < C.size(); ++i) {
| ~~~~~~^~~~~~~~~~
stations.cpp:51:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (int i = 1; i + 1 < 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... |