#include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1010;
ll dis[N][N];
int n;
int p[N];
int fr(int i) {
return p[i] == i ? i : p[i] = fr(p[i]);
}
ll d(int i, int j) {
if (i == j) return 0;
if (!dis[i][j]) return dis[i][j] = dis[j][i] = get_distance(i, j);
return dis[i][j];
}
void find_roads(int NN, int Q, int A[], int B[], int W[]) {
n = NN;
if (Q == 12000) {
ll mx = 0;
int idx = 0;
for (int i = 2;i <= n;i++) {
if (d(1, i) > mx) {
mx = d(1, i);
idx = i;
}
}
vector<pair<ll, int>> v;
for (int i = 1;i <= n;i++) {
v.push_back({ d(idx, i), i });
}
sort(v.begin(), v.end());
for (int i = 1;i < n;i++) {
A[i - 1] = v[i - 1].second;
B[i - 1] = v[i].second;
W[i - 1] = v[i].first - v[i - 1].first;
}
return;
}
vector<pair<int, pair<int, int>>> v;
for (int i = 1;i <= n;i++) {
p[i] = i;
for (int j = i + 1;j <= n;j++) {
v.push_back({ d(i, j), {i, j} });
}
}
int idx = 0;
sort(v.begin(), v.end());
for (auto& x : v) {
int u = x.second.first, v = x.second.second;
if (fr(u) == fr(v)) continue;
p[fr(u)] = fr(v);
A[idx] = u, B[idx] = v, W[idx] = x.first;
idx++;
}
return;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
15232 KB |
Correct: 498501 out of 500000 queries used. |
2 |
Correct |
87 ms |
15040 KB |
Correct: 499500 out of 500000 queries used. |
3 |
Correct |
87 ms |
16112 KB |
Correct: 492528 out of 500000 queries used. |
4 |
Correct |
86 ms |
15820 KB |
Correct: 494515 out of 500000 queries used. |
5 |
Correct |
87 ms |
15308 KB |
Correct: 498501 out of 500000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
15232 KB |
Correct: 498501 out of 500000 queries used. |
2 |
Correct |
87 ms |
15040 KB |
Correct: 499500 out of 500000 queries used. |
3 |
Correct |
87 ms |
16112 KB |
Correct: 492528 out of 500000 queries used. |
4 |
Correct |
86 ms |
15820 KB |
Correct: 494515 out of 500000 queries used. |
5 |
Correct |
87 ms |
15308 KB |
Correct: 498501 out of 500000 queries used. |
6 |
Incorrect |
67 ms |
15744 KB |
Reported list of edges differ from actual. |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8028 KB |
Correct: 1979 out of 12000 queries used. |
2 |
Correct |
2 ms |
7756 KB |
Correct: 1983 out of 12000 queries used. |
3 |
Correct |
2 ms |
7772 KB |
Correct: 1997 out of 12000 queries used. |
4 |
Correct |
2 ms |
7772 KB |
Correct: 1983 out of 12000 queries used. |
5 |
Correct |
2 ms |
8028 KB |
Correct: 1979 out of 12000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8028 KB |
Correct: 1979 out of 12000 queries used. |
2 |
Correct |
2 ms |
7756 KB |
Correct: 1983 out of 12000 queries used. |
3 |
Correct |
2 ms |
7772 KB |
Correct: 1997 out of 12000 queries used. |
4 |
Correct |
2 ms |
7772 KB |
Correct: 1983 out of 12000 queries used. |
5 |
Correct |
2 ms |
8028 KB |
Correct: 1979 out of 12000 queries used. |
6 |
Correct |
2 ms |
8280 KB |
Correct: 1993 out of 12000 queries used. |
7 |
Correct |
2 ms |
7772 KB |
Correct: 1989 out of 12000 queries used. |
8 |
Correct |
2 ms |
7772 KB |
Correct: 1997 out of 12000 queries used. |
9 |
Correct |
2 ms |
8284 KB |
Correct: 1991 out of 12000 queries used. |
10 |
Correct |
2 ms |
7516 KB |
Correct: 1985 out of 12000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
15232 KB |
Correct: 498501 out of 500000 queries used. |
2 |
Correct |
87 ms |
15040 KB |
Correct: 499500 out of 500000 queries used. |
3 |
Correct |
87 ms |
16112 KB |
Correct: 492528 out of 500000 queries used. |
4 |
Correct |
86 ms |
15820 KB |
Correct: 494515 out of 500000 queries used. |
5 |
Correct |
87 ms |
15308 KB |
Correct: 498501 out of 500000 queries used. |
6 |
Incorrect |
67 ms |
15744 KB |
Reported list of edges differ from actual. |
7 |
Halted |
0 ms |
0 KB |
- |