이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include "stations.h"
using namespace std;
vector <vector <int>> g(1e3);
vector <int> sz(1e3, 0);
vector <int> lbl;
void dfs1(int x) {
sz[x] = 1;
for (int i : g[x]) {
if (sz[i]) continue;
dfs1(i);
sz[x] += sz[i];
}
}
void dfs2(int x, int l, int r, bool b) {
if (b) { lbl[x] = l; l++; }
else { lbl[x] = r; r--; }
for (int i : g[x]) {
if (lbl[i] > -1) continue;
dfs2(i, l, l + sz[i] - 1, !b);
l += sz[i];
}
}
vector <int> label(int n, int k, vector <int> u, vector <int> v) {
lbl.assign(n, -1);
for (int i = 0; i < n - 1; i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs1(0);
dfs2(0, 0, n - 1, true);
cout << endl;
for (int i : lbl) cout << i << endl;
cout << endl;
return lbl;
}
int find_next_station(int s, int t, vector <int> c) {
if (c.size() == 1) return c[0];
if (s == 0) {
for (int i = 0; i < c.size(); i++) if (t <= c[i]) return c[i];
}
if (s < c[0]) {
if (t < s || c[c.size() - 2] < t) return c.back();
for (int i = 0; i < c.size() - 1; i++) if (t <= c[i]) return c[i];
}
if (c.back() < s) {
if (t < c[1] || s < t) return c[0];
for (int i = c.size() - 1; i > 0; i--) if (t >= c[i]) return c[i];
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:46:21: 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(); i++) if (t <= c[i]) return c[i];
| ~~^~~~~~~~~~
stations.cpp:50:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0; i < c.size() - 1; i++) if (t <= c[i]) return c[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... |