이 제출은 이전 버전의 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;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n), in(n);
// vector<int> adj[n + 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]);
// }
// int start = -1;
// vector<int> order;
// for(int i = 0; i < n; i++) {
// if(in[i] == 1) {
// start = i;
// break;
// }
// }
// // assert(start != -1);
// // dfs(start, -1);
// auto bfs = [&](int node)-> void {
// queue<pair<int, int>> q;
// q.push({node, -1});
// while(!q.empty()) {
// auto u = q.front();
// q.pop();
// order.push_back(u.first);
// for(auto i: adj[u.first]) {
// if(i == u.second) continue;
// q.push({i, u.first});
// }
// }
// };
// bfs(start);
for (int i = 0; i < n; i++) {
labels[i] = i;
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
set<int> parentsFirst, parentsSecond;
int new_s = s;
while(new_s) {
parentsFirst.insert(new_s);
new_s /= 2;
}
parentsFirst.insert(0);
int new_t = t, lca = -1;
while(true) {
parentsSecond.insert(new_t);
if(parentsFirst.find(new_t) != parentsFirst.end()) {
parentsFirst.erase(new_t);
lca = new_t;
break;
}
if(!new_t) {
break;
}
if(new_t % 2 == 0) new_t--;
new_t /= 2;
}
bool f1 = false, f2 = false;
int answ = -1;
for(auto i: c) {
if(parentsFirst.find(i) != parentsFirst.end()) {
f1 = true;
}
if(parentsSecond.find(i) != parentsSecond.end()) {
f2 = true;
}
}
if(f1 && f2) {
// this is lca
int mx = -1;
for(auto i: c) {
if(parentsSecond.find(i) != parentsSecond.end()) {
mx = max(mx, i);
}
}
return mx;
} else if(f1) {
int mn = 1005;
for(auto i: c) {
if(parentsFirst.find(i) != parentsFirst.end()) {
mn = min(mn, i);
}
}
return mn;
} else {
int mx = -1;
for(auto i: c) {
if(parentsSecond.find(i) != parentsSecond.end()) {
mx = max(mx, i);
}
}
return mx;
}
return c[0];
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:79:18: warning: variable 'lca' set but not used [-Wunused-but-set-variable]
79 | int new_t = t, lca = -1;
| ^~~
stations.cpp:95:7: warning: unused variable 'answ' [-Wunused-variable]
95 | int answ = -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... |