이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
vector<int> graph [1000*1000];
vector<int> assign;
int curT;
void dfs(int x, int p = -1, int h = 0) {
if (h%2 == 0) {
assign[x] = curT;
curT++;
}
for (int y : graph[x]) if (y != p) {
dfs(y, x, h+1);
}
if (h%2 == 1) {
assign[x] = curT;
curT++;
}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
for (int i = 0; i < n; i++) {
graph[i].clear();
}
for (int i = 0; i < n-1; i++) {
graph[u[i]].push_back(v[i]);
graph[v[i]].push_back(u[i]);
}
assign = vector<int>(n, -1);
curT = 0;
dfs(0);
return assign;
}
int find_next_station(int curL, int tarL, std::vector<int> adj) {
sort(adj.begin(), adj.end());
if (curL == 0) { // the root
for (int i : adj) {
if (tarL <= i) {
return i;
}
}
assert(false);
return -1;
}
vector<pair<int, pair<int, int>>> ints;
int parent;
if (adj[0] > curL) {
parent = adj.back();
for (int i = 0; i < adj.size()-1; i++) {
int bef = curL+1;
if (i) bef = adj[i-1]+1;
ints.push_back({adj[i], {bef, adj[i]}});
}
}
else {
parent = adj[0];
assert(adj.back() < curL);
for (int i = 1; i < adj.size(); i++) {
int aft = curL-1;
if (i+1 < adj.size()) aft = adj[i+1]-1;
ints.push_back({adj[i], {adj[i], aft}});
}
}
for (auto i : ints) {
if (i.second.second <= tarL && tarL <= i.second.second) {
return i.first;
}
}
return parent;
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:54:21: 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 < adj.size()-1; i++) {
| ~~^~~~~~~~~~~~~~
stations.cpp:63:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (int i = 1; i < adj.size(); i++) {
| ~~^~~~~~~~~~~~
stations.cpp:65:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | if (i+1 < adj.size()) aft = adj[i+1]-1;
| ~~~~^~~~~~~~~~~~
# | 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... |