#include "bits/stdc++.h"
#include "citymapping.h"
using namespace std;
using ll = long long;
#define eb emplace_back
#define nl endl
void find_roads(int N, int Q, int A[], int B[], int W[]) {
ll dist[N + 1][N + 1];
for(int i = 1; i <= N; ++i) {
dist[i][i] = 0;
for(int j = i + 1; j <= N; ++j) {
dist[i][j] = dist[j][i] = abs(get_distance(i, j));
}
}
/* for(int i = 1; i <= N; ++i) { */
/* for(int j = 1; j <= N; ++j) { */
/* cout << dist[i][j] << ' '; */
/* } */
/* cout << nl; */
/* } */
/* cout << nl; */
vector<pair<int, ll>> adj[N + 1];
for(int i = 1; i <= N; ++i) {
int x = (i == 1 ? 2 : 1);
for(int j = 1; j <= N; ++j) {
if(j == i) continue;
if(dist[i][j] < dist[i][x]) x = j;
}
adj[i].eb(x, dist[i][x]);
int y = 0;
for(int j = 1; j <= N; ++j) {
if(j == i || j == x) continue;
if(dist[i][j] == dist[i][x] + dist[x][j]) continue;
if(y == 0 || dist[i][j] < dist[i][y]) y = j;
}
if(y == 0) continue;
adj[i].eb(y, dist[i][y]);
/* continue; */
int z = 0;
for(int j = 1; j <= N; ++j) {
if(j == i || j == x || j == y) continue;
if(dist[i][j] == dist[i][x] + dist[x][j]) continue;
if(dist[i][j] == dist[i][y] + dist[y][j]) continue;
if(z == 0 || dist[i][j] < dist[i][z]) z = j;
}
if(z == 0) continue;
adj[i].eb(z, dist[i][z]);
}
int ptr = 0;
for(int i = 1; i <= N; ++i) {
for(auto [j, w] : adj[i]) {
if(j <= i) continue;
A[ptr] = i; B[ptr] = j; W[ptr] = w;
++ptr;
/* cout << i << ' ' << j << ' ' << w << nl; */
}
}
return;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
8264 KB |
Correct: 498501 out of 500000 queries used. |
2 |
Correct |
46 ms |
8400 KB |
Correct: 499500 out of 500000 queries used. |
3 |
Correct |
38 ms |
8152 KB |
Correct: 492528 out of 500000 queries used. |
4 |
Correct |
35 ms |
8184 KB |
Correct: 494515 out of 500000 queries used. |
5 |
Correct |
47 ms |
8396 KB |
Correct: 498501 out of 500000 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
8264 KB |
Correct: 498501 out of 500000 queries used. |
2 |
Correct |
46 ms |
8400 KB |
Correct: 499500 out of 500000 queries used. |
3 |
Correct |
38 ms |
8152 KB |
Correct: 492528 out of 500000 queries used. |
4 |
Correct |
35 ms |
8184 KB |
Correct: 494515 out of 500000 queries used. |
5 |
Correct |
47 ms |
8396 KB |
Correct: 498501 out of 500000 queries used. |
6 |
Correct |
44 ms |
8248 KB |
Correct: 495510 out of 500000 queries used. |
7 |
Correct |
45 ms |
8268 KB |
Correct: 497503 out of 500000 queries used. |
8 |
Correct |
40 ms |
8256 KB |
Correct: 497503 out of 500000 queries used. |
9 |
Correct |
37 ms |
8232 KB |
Correct: 495510 out of 500000 queries used. |
10 |
Correct |
47 ms |
8268 KB |
Correct: 496506 out of 500000 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
8020 KB |
Too many calls to get_distance(). |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
8020 KB |
Too many calls to get_distance(). |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
8264 KB |
Correct: 498501 out of 500000 queries used. |
2 |
Correct |
46 ms |
8400 KB |
Correct: 499500 out of 500000 queries used. |
3 |
Correct |
38 ms |
8152 KB |
Correct: 492528 out of 500000 queries used. |
4 |
Correct |
35 ms |
8184 KB |
Correct: 494515 out of 500000 queries used. |
5 |
Correct |
47 ms |
8396 KB |
Correct: 498501 out of 500000 queries used. |
6 |
Correct |
44 ms |
8248 KB |
Correct: 495510 out of 500000 queries used. |
7 |
Correct |
45 ms |
8268 KB |
Correct: 497503 out of 500000 queries used. |
8 |
Correct |
40 ms |
8256 KB |
Correct: 497503 out of 500000 queries used. |
9 |
Correct |
37 ms |
8232 KB |
Correct: 495510 out of 500000 queries used. |
10 |
Correct |
47 ms |
8268 KB |
Correct: 496506 out of 500000 queries used. |
11 |
Incorrect |
4 ms |
8020 KB |
Too many calls to get_distance(). |
12 |
Halted |
0 ms |
0 KB |
- |