#include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll inf = 1e15;
void find_roads(int N, int Q, int A[], int B[], int W[]) {
int r = -1;
ll mx = 0;
for (int i = 1; i < N; i++) {
assert(Q--);
ll s = get_distance(1, i + 1);
if (s > mx) {
mx = s;
r = i;
}
}
vector<ll> dis(N);
for (int i = 0; i < N; i++) {
assert(Q--);
dis[i] = i == r ? 0 : get_distance(r + 1, i + 1);
}
vector<int> p(N);
iota(p.begin(), p.end(), 0);
sort(p.begin(), p.end(), [&](int i, int j) {
return dis[i] < dis[j];
});
vector<vector<int>> d(N);
d[0].push_back(r);
for (int i = 1; i < N; i++) {
int v = p[i];
vector<bool> f(N);
int lo = 0, hi = N - 1;
while (lo < hi) {
int mi = (lo + hi + 1) / 2;
bool ok = 0;
for (int x : d[mi]) {
assert(Q--);
if (dis[v] - dis[x] == get_distance(x + 1, v + 1)) {
f[x] = 1;
ok = 1;
}
}
if (ok) {
lo = mi;
} else {
hi = mi - 1;
}
}
int u = -1;
for (int x : d[lo]) {
if (f[x]) {
u = x;
}
}
if (u == -1) {
for (int x : d[lo]) {
assert(Q--);
if (dis[v] - dis[x] == get_distance(x + 1, v + 1)) {
u = x;
break;
}
}
}
A[i - 1] = u + 1;
B[i - 1] = v + 1;
W[i - 1] = dis[v] - dis[u];
d[lo + 1].push_back(v);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Correct: 7028 out of 500000 queries used. |
2 |
Correct |
2 ms |
468 KB |
Correct: 11582 out of 500000 queries used. |
3 |
Correct |
10 ms |
468 KB |
Correct: 182922 out of 500000 queries used. |
4 |
Correct |
11 ms |
480 KB |
Correct: 221969 out of 500000 queries used. |
5 |
Correct |
6 ms |
468 KB |
Correct: 71533 out of 500000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Correct: 7028 out of 500000 queries used. |
2 |
Correct |
2 ms |
468 KB |
Correct: 11582 out of 500000 queries used. |
3 |
Correct |
10 ms |
468 KB |
Correct: 182922 out of 500000 queries used. |
4 |
Correct |
11 ms |
480 KB |
Correct: 221969 out of 500000 queries used. |
5 |
Correct |
6 ms |
468 KB |
Correct: 71533 out of 500000 queries used. |
6 |
Correct |
2 ms |
468 KB |
Correct: 7009 out of 500000 queries used. |
7 |
Correct |
2 ms |
468 KB |
Correct: 11611 out of 500000 queries used. |
8 |
Correct |
10 ms |
468 KB |
Correct: 179877 out of 500000 queries used. |
9 |
Correct |
9 ms |
468 KB |
Correct: 187367 out of 500000 queries used. |
10 |
Correct |
6 ms |
468 KB |
Correct: 66374 out of 500000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Correct: 6977 out of 12000 queries used. |
2 |
Correct |
2 ms |
468 KB |
Correct: 6989 out of 12000 queries used. |
3 |
Correct |
2 ms |
468 KB |
Correct: 7033 out of 12000 queries used. |
4 |
Correct |
2 ms |
468 KB |
Correct: 6989 out of 12000 queries used. |
5 |
Correct |
2 ms |
468 KB |
Correct: 6977 out of 12000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Correct: 6977 out of 12000 queries used. |
2 |
Correct |
2 ms |
468 KB |
Correct: 6989 out of 12000 queries used. |
3 |
Correct |
2 ms |
468 KB |
Correct: 7033 out of 12000 queries used. |
4 |
Correct |
2 ms |
468 KB |
Correct: 6989 out of 12000 queries used. |
5 |
Correct |
2 ms |
468 KB |
Correct: 6977 out of 12000 queries used. |
6 |
Correct |
2 ms |
468 KB |
Correct: 7022 out of 12000 queries used. |
7 |
Correct |
2 ms |
468 KB |
Correct: 7009 out of 12000 queries used. |
8 |
Correct |
2 ms |
516 KB |
Correct: 7033 out of 12000 queries used. |
9 |
Correct |
2 ms |
468 KB |
Correct: 7016 out of 12000 queries used. |
10 |
Correct |
2 ms |
464 KB |
Correct: 6996 out of 12000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Correct: 7028 out of 500000 queries used. |
2 |
Correct |
2 ms |
468 KB |
Correct: 11582 out of 500000 queries used. |
3 |
Correct |
10 ms |
468 KB |
Correct: 182922 out of 500000 queries used. |
4 |
Correct |
11 ms |
480 KB |
Correct: 221969 out of 500000 queries used. |
5 |
Correct |
6 ms |
468 KB |
Correct: 71533 out of 500000 queries used. |
6 |
Correct |
2 ms |
468 KB |
Correct: 7009 out of 500000 queries used. |
7 |
Correct |
2 ms |
468 KB |
Correct: 11611 out of 500000 queries used. |
8 |
Correct |
10 ms |
468 KB |
Correct: 179877 out of 500000 queries used. |
9 |
Correct |
9 ms |
468 KB |
Correct: 187367 out of 500000 queries used. |
10 |
Correct |
6 ms |
468 KB |
Correct: 66374 out of 500000 queries used. |
11 |
Correct |
2 ms |
468 KB |
Correct: 6977 out of 12000 queries used. |
12 |
Correct |
2 ms |
468 KB |
Correct: 6989 out of 12000 queries used. |
13 |
Correct |
2 ms |
468 KB |
Correct: 7033 out of 12000 queries used. |
14 |
Correct |
2 ms |
468 KB |
Correct: 6989 out of 12000 queries used. |
15 |
Correct |
2 ms |
468 KB |
Correct: 6977 out of 12000 queries used. |
16 |
Correct |
2 ms |
468 KB |
Correct: 7022 out of 12000 queries used. |
17 |
Correct |
2 ms |
468 KB |
Correct: 7009 out of 12000 queries used. |
18 |
Correct |
2 ms |
516 KB |
Correct: 7033 out of 12000 queries used. |
19 |
Correct |
2 ms |
468 KB |
Correct: 7016 out of 12000 queries used. |
20 |
Correct |
2 ms |
464 KB |
Correct: 6996 out of 12000 queries used. |
21 |
Correct |
2 ms |
556 KB |
Correct: 7009 out of 25000 queries used. |
22 |
Correct |
3 ms |
468 KB |
Correct: 10929 out of 25000 queries used. |
23 |
Correct |
2 ms |
468 KB |
Correct: 10695 out of 25000 queries used. |
24 |
Correct |
2 ms |
472 KB |
Correct: 11061 out of 25000 queries used. |
25 |
Runtime error |
3 ms |
724 KB |
Execution killed with signal 6 |
26 |
Halted |
0 ms |
0 KB |
- |