이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"stations.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
int hi = -1;
vector<int> L, R;
vector<bool> flor;
void dfs(int s, int p, bool flr) {
flor[s] = flr;
bool leaf = 1;
if(!flr) {
L[s] = ++hi;
}
for(auto& u : adj[s]) {
if(u == p) continue;
leaf = 0;
dfs(u, s, flr ^ 1);
}
if(flr) {
R[s] = ++hi;
}
}
vector<int> label(int N, int K, vector<int> u, vector<int> v) {
flor.resize(N);
L.resize(N);
R.resize(N);
adj.resize(N);
for(auto& I : adj) I.clear();
for(int i = 0; i < (int)u.size(); ++i) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0, -1, 0);
vector<int> labels(N);
for(int i = 0; i < N; ++i) labels[i] = (flor[i] ? R[i]: L[i]);
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if(s == 0) {
pair<int, int> T = {t, t};
vector<pair<int, int>> C((int)c.size());
C[0] = {1, c[0]};
for(int i = 1; i < (int)c.size(); ++i) {
C[i] = {c[i - 1] + 1, c[i]};
}
for(int i = 0; i < (int)c.size(); ++i) {
if(C[i].first <= T.second && C[i].second >= T.second) return c[i];
}
}
if(s < c[0]) {
pair<int, int> S = {s, c.back() - 1}, T = {t, t};
vector<pair<int, int>> C((int)c.size());
C[0] = {s + 1, c[0]};
C.back() = {s, c.back()};
for(int i = 1; i + 1 < (int)c.size(); ++i) {
C[i] = {c[i - 1] + 1, c[i]};
}
for(int i = 0; i + 1 < (int)c.size(); ++i) {
if(C[i].first <= T.second && C[i].second >= T.second) return c[i];
}
return c.back();
}
pair<int, int> S = {c[0] + 1, s}, T = {t, t};
vector<pair<int, int>> C((int)c.size());
C.back() = {c.back(), s - 1};
C[0] = {c[0], s};
for(int i = 1; i + 1 < (int)c.size(); ++i) {
C[i] = {c[i], c[i + 1] - 1};
}
for(int i = 1; i < (int)c.size(); ++i) {
if(C[i].first <= T.second && C[i].second >= T.second) return c[i];
}
return c[0];
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'void dfs(int, int, bool)':
stations.cpp:12:7: warning: variable 'leaf' set but not used [-Wunused-but-set-variable]
12 | bool leaf = 1;
| ^~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:55:18: warning: variable 'S' set but not used [-Wunused-but-set-variable]
55 | pair<int, int> S = {s, c.back() - 1}, T = {t, t};
| ^
stations.cpp:67:17: warning: variable 'S' set but not used [-Wunused-but-set-variable]
67 | pair<int, int> S = {c[0] + 1, s}, T = {t, t};
| ^
# | 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... |