#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>> ch(N);
for (int i = 1; i < N; i++) {
int x = r, v = p[i];
while (1) {
if (ch[x].empty()) {
A[i - 1] = x + 1;
B[i - 1] = v + 1;
W[i - 1] = dis[v] - dis[x];
ch[x].push_back(v);
break;
}
if (x == r) {
x = ch[x][0];
continue;
}
if (ch[x].size() == 2) {
assert(Q--);
assert(Q--);
if (dis[v] - dis[ch[x][0]] == get_distance(v + 1, ch[x][0] + 1)) {
x = ch[x][0];
} else {
x = ch[x][1];
}
} else {
assert(Q--);
if (dis[v] - dis[ch[x][0]] != get_distance(v + 1, ch[x][0] + 1)) {
A[i - 1] = x + 1;
B[i - 1] = v + 1;
W[i - 1] = dis[v] - dis[x];
ch[x].push_back(v);
break;
}
x = ch[x][0];
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
500 KB |
Correct: 498502 out of 500000 queries used. |
2 |
Correct |
19 ms |
500 KB |
Correct: 250999 out of 500000 queries used. |
3 |
Correct |
3 ms |
468 KB |
Correct: 26270 out of 500000 queries used. |
4 |
Correct |
2 ms |
468 KB |
Correct: 15476 out of 500000 queries used. |
5 |
Correct |
7 ms |
468 KB |
Correct: 85875 out of 500000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
500 KB |
Correct: 498502 out of 500000 queries used. |
2 |
Correct |
19 ms |
500 KB |
Correct: 250999 out of 500000 queries used. |
3 |
Correct |
3 ms |
468 KB |
Correct: 26270 out of 500000 queries used. |
4 |
Correct |
2 ms |
468 KB |
Correct: 15476 out of 500000 queries used. |
5 |
Correct |
7 ms |
468 KB |
Correct: 85875 out of 500000 queries used. |
6 |
Correct |
23 ms |
552 KB |
Correct: 495511 out of 500000 queries used. |
7 |
Correct |
20 ms |
596 KB |
Correct: 249998 out of 500000 queries used. |
8 |
Correct |
3 ms |
472 KB |
Correct: 22214 out of 500000 queries used. |
9 |
Correct |
2 ms |
468 KB |
Correct: 15379 out of 500000 queries used. |
10 |
Correct |
7 ms |
508 KB |
Correct: 83121 out of 500000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
852 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
852 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
500 KB |
Correct: 498502 out of 500000 queries used. |
2 |
Correct |
19 ms |
500 KB |
Correct: 250999 out of 500000 queries used. |
3 |
Correct |
3 ms |
468 KB |
Correct: 26270 out of 500000 queries used. |
4 |
Correct |
2 ms |
468 KB |
Correct: 15476 out of 500000 queries used. |
5 |
Correct |
7 ms |
468 KB |
Correct: 85875 out of 500000 queries used. |
6 |
Correct |
23 ms |
552 KB |
Correct: 495511 out of 500000 queries used. |
7 |
Correct |
20 ms |
596 KB |
Correct: 249998 out of 500000 queries used. |
8 |
Correct |
3 ms |
472 KB |
Correct: 22214 out of 500000 queries used. |
9 |
Correct |
2 ms |
468 KB |
Correct: 15379 out of 500000 queries used. |
10 |
Correct |
7 ms |
508 KB |
Correct: 83121 out of 500000 queries used. |
11 |
Runtime error |
2 ms |
852 KB |
Execution killed with signal 6 |
12 |
Halted |
0 ms |
0 KB |
- |