이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifndef WAIMAI
#include "stations.h"
#endif
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 1005;
vector<int> adj[SIZE];
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n, -1);
iota(labels.begin(), labels.end(), 0);
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
int hs = __lg(s + 1), ht = __lg(t + 1);
int x = s, y = t, hx = hs, hy = ht;
while (x != y) {
if (hx > hy) x = (x - 1) / 2, hx--;
else y = (y - 1) / 2, hy--;
}
debug(s, t, x);
if (x == s) {
while ((t - 1) / 2 > s) t = (t - 1) / 2;
return t;
}
return (s - 1) / 2;
}
/*
in1
1
5 10
0 1
1 2
1 3
2 4
2
2 0 1
1 3 3
out1
9
1
3
case1
1
5 100
4 2
2 3
3 0
0 1
2
2 1 3
1 4 0
case2
1
7 10
0 1
0 2
1 3
1 4
2 5
2 6
3
4 5 1
6 0 2
1 4 4
*/
#ifdef WAIMAI
static int max_label = 0;
static int r, n, k, q;
static vector<int> u, v, labels, answers;
static map<int, int> reverse_labels;
static vector<vector<int>> adjlist;
static int s, t, w;
static vector<int> c;
int main() {
assert(scanf("%d", &r) == 1);
for (int tc = 0; tc < r; tc++) {
assert(scanf("%d%d", &n, &k) == 2);
u.resize(n - 1);
v.resize(n - 1);
adjlist.clear();
adjlist.resize(n);
for (int i = 0; i < n - 1; i++) {
assert(scanf("%d%d", &u[i], &v[i]) == 2);
adjlist[u[i]].push_back(v[i]);
adjlist[v[i]].push_back(u[i]);
}
labels = label(n, k, u, v);
if ((int)labels.size() != n) {
printf("Number of labels not equal to %d\n", n);
exit(0);
}
reverse_labels.clear();
for (int i = 0; i < n; i++) {
if (labels[i] < 0 || labels[i] > k) {
printf("Label not in range 0 to %d\n", k);
exit(0);
}
if (reverse_labels.find(labels[i]) != reverse_labels.end()) {
printf("Labels not unique\n");
exit(0);
}
reverse_labels[labels[i]] = i;
if (labels[i] > max_label) {
max_label = labels[i];
}
}
assert(scanf("%d", &q) == 1);
for (int i = 0; i < q; i++) {
assert(scanf("%d%d%d", &s, &t, &w) == 3);
c.clear();
for (int v : adjlist[s]) {
c.push_back(labels[v]);
}
sort(c.begin(), c.end());
int answer = find_next_station(labels[s], labels[t], c);
if (!binary_search(c.begin(), c.end(), answer)) {
printf("Label %d returned by find_next_station not found in c\n", answer);
exit(0);
}
answers.push_back(reverse_labels[answer]);
}
}
printf("%d\n", max_label);
for (int index : answers) {
printf("%d\n", index);
}
exit(0);
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:16:20: warning: statement has no effect [-Wunused-value]
16 | #define debug(...) 7122
| ^~~~
stations.cpp:42:5: note: in expansion of macro 'debug'
42 | debug(s, t, x);
| ^~~~~
# | 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... |