#include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
const int MAXN = 1000;
int t = 0;
mt19937 rng(0);
ll dist[2][MAXN];
void make_ans(vector<int> &vals, int a[], int b[], int w[]) {
if (vals.size() == 1) return;
if (vals.size() == 2) {
a[t] = vals[0];
b[t] = vals[1];
w[t] = get_distance(vals[0], vals[1]);
t++;
return;
}
int n = vals.size();
int f = rng()%n;
int mx = -1;
for (int i = 0; i < n; i++) {
if (i == f) continue;
dist[0][i] = get_distance(vals[i], vals[f]);
if (mx == -1 || dist[0][i] > dist[0][mx]) mx = i;
}
dist[0][f] = 0;
for (int i = 0; i < n; i++) {
if (i == f || i == mx) continue;
dist[1][i] = get_distance(vals[i], vals[mx]);
}
dist[1][mx] = 0;
dist[1][f] = dist[0][mx];
vector<pli> path;
map<ll, vector<int>> buckets;
for (int i = 0; i < n; i++) {
if (dist[0][i]+dist[1][i] == dist[0][mx]) {
path.push_back(pli(dist[0][i], i));
}
}
sort(path.begin(), path.end());
for (int i = 0; i < path.size()-1; i++) {
a[t] = vals[path[i].second];
b[t] = vals[path[i+1].second];
w[t] = dist[0][i+1]-dist[0][i];
t++;
}
for (int i = 0; i < n; i++) {
buckets[dist[1][i]-dist[0][i]].push_back(vals[i]);
}
for (auto it: buckets) {
make_ans(it.second, a, b, w);
}
}
void find_roads(int n, int q, int a[], int b[], int w[]) {
vector<int> v(n);
iota(v.begin(), v.end(), 1);
make_ans(v, a, b, w);
assert(t == n-1);
return;
}
Compilation message
citymapping.cpp: In function 'void make_ans(std::vector<int>&, int*, int*, int*)':
citymapping.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 0; i < path.size()-1; i++) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Reported list of edges differ from actual. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Reported list of edges differ from actual. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
596 KB |
Reported list of edges differ from actual. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
596 KB |
Reported list of edges differ from actual. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Reported list of edges differ from actual. |
2 |
Halted |
0 ms |
0 KB |
- |