이 제출은 이전 버전의 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) ? in[cur] : out[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) return S;
sort(C.begin(), C.end());
if (T < S || C.back() < T) return C[0];
for (int i = 0; i < C.size(); ++i) {
if (C[i] < S) continue;
if (i + 1 == C.size() || T < C[i + 1]) return C[i];
}
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (int i = 0; i < C.size(); ++i) {
| ~~^~~~~~~~~~
stations.cpp:41:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | if (i + 1 == C.size() || T < C[i + 1]) return C[i];
| ~~~~~~^~~~~~~~~~~
stations.cpp:43:1: warning: control reaches end of non-void function [-Wreturn-type]
43 | }
| ^
# | 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... |