이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define idata vector<int>
#define graph vector<idata>
graph roads;
int component = 0;
void dfs (int node, int parent, bool type, idata &labels) {
if (type) {
labels[node] = component;
component ++;
}
for (int next : roads[node]) if (next != parent)
dfs(next, node, !type, labels);
if (!type) {
labels[node] = component;
component ++;
}
}
idata label(int n, int k, idata u, idata v) {
component = 0;
roads.clear();
roads.resize(n);
for (int i = 0; i + 1 < n; i ++) {
roads[u[i]].push_back(v[i]);
roads[v[i]].push_back(u[i]);
}
idata labels(n);
dfs(0, -1, true, labels);
return labels;
}
int find_next_station(int s, int t, idata c) {
bool is_root = s == 0;
bool is_revr = c[0] < s;
if (is_revr) {
for (int i = 0; i < c.size(); i ++)
c[i] = - c[i];
s = -s;
t = -t;
}
sort(c.begin(), c.end());
int size = c.size();
if (!is_root) size --;
int result = c[c.size() - 1];
for (int h = 0; h < size; h ++) {
if (s < t && t <= c[h]) {
result = c[h];
break ;
}
}
return is_revr ? -result : result;
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 0; i < 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... |