이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int((x).size()))
#define len(x) (int)x.length()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(x) cout << #x << " " << x << endl;
#define uniq(x) x.resize(unique(all(x)) - x.begin());
#define pb push_back
#define ld long double
#define ll long long
void pr(vector<int>& a) {
cerr << "arr" << " ";
for(auto i: a) {
cerr << i << " ";
} cerr << endl;
}
const int N = 2e5 + 10;
int tin[N], tout[N];
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n), in(n);
vector<int> adj[n + 1];
int timer = 1;
for(int i = 0; i < n - 1; i++) {
in[u[i]]++, in[v[i]]++;
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
function<void(int node, int parent)> dfs;
dfs = [&](int node, int parent) {
tin[node] = timer++;
for(auto i: adj[node]) {
if(i == parent) continue;
dfs(i, node);
}
tout[node] = timer - 1;
};
dfs(0, -1);
for (int i = 0; i < n; i++) {
labels[i] = tin[i] * 10000 + tout[i];
// cerr << i << " " << labels[i] << endl;
tin[i] = tout[i] = 0;
adj[i].clear();
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
int s_tu = s % 10000, s_ti = s / 10000;
int t_tu = t % 10000, t_ti = t / 10000;
if(t_ti >= s_ti && t_tu <= s_tu) {
// t's subtree
for(auto i: c) {
int new_tu = i % 10000, new_ti = i / 10000;
if(t_ti >= new_ti && t_tu <= new_tu) {
return i;
}
}
} else {
for(auto i: c) {
int new_tu = i % 10000, new_ti = i / 10000;
if(new_ti < s_ti) {
return i;
}
}
}
return c[0];
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:74:11: warning: unused variable 'new_tu' [-Wunused-variable]
74 | int new_tu = i % 10000, new_ti = i / 10000;
| ^~~~~~
# | 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... |