This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;
// long long get_distance(int X, int Y);
using lint = long long;
const lint inf = 1e18;
int n, t=0, *A, *B, *W;
void f(vector<int> v) {
int x = v[0], y = v[0], z = v[0];
vector<lint> a, b, c, d;
lint mxd;
mxd = 0;
for (int i : v) {
lint d = get_distance(x, i);
if (d > mxd) mxd = d, y = i;
a.push_back(d);
}
mxd = 0;
for (int i : v) {
lint d = get_distance(y, i);
if (d > mxd) mxd = d, z = i;
b.push_back(d);
}
for (int i : v) c.push_back(get_distance(z, i));
for (int i=0; i<v.size(); i++) d.push_back(b[i] - c[i]);
vector<int> ind;
for (int i=0; i<v.size(); i++) ind.push_back(i);
sort(ind.begin(), ind.end(), [&](int x, int y) { return (d[x] < d[y]) or (d[x] == d[y] and b[x] < b[y]); });
vector<lint> tb, td;
vector<int> tv;
for (int i=0; i<b.size(); i++) tb.push_back(b[ind[i]]);
b = tb;
for (int i=0; i<d.size(); i++) td.push_back(d[ind[i]]);
d = td;
for (int i=0; i<v.size(); i++) tv.push_back(v[ind[i]]);
v = tv;
for (int i=0; i<v.size(); ) {
vector<int> u;
int k = i;
while (i+1<v.size() and d[i] == d[i+1]) {
u.push_back(i+1);
i++;
} i++;
if (i < v.size()) {
A[t] = v[k]; B[t] = v[i]; W[t] = b[i] - b[k]; t++;
}
if (!u.empty()) {
A[t] = v[k]; B[t] = v[u[0]]; W[t] = b[u[0]] - b[k]; t++;
}
if (u.size() >= 2) {
for (int &i : u) i = v[i];
f(u);
}
}
}
void find_roads(int N, int Q, int a[], int b[], int w[]) {
n = N; A = a; B = b; W = w;
vector<int> v;
for (int i=1; i<=n; i++) v.push_back(i);
f(v);
}
Compilation message (stderr)
citymapping.cpp: In function 'void f(std::vector<int>)':
citymapping.cpp:33:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<v.size(); i++) d.push_back(b[i] - c[i]);
~^~~~~~~~~
citymapping.cpp:36:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<v.size(); i++) ind.push_back(i);
~^~~~~~~~~
citymapping.cpp:42:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<b.size(); i++) tb.push_back(b[ind[i]]);
~^~~~~~~~~
citymapping.cpp:44:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<d.size(); i++) td.push_back(d[ind[i]]);
~^~~~~~~~~
citymapping.cpp:46:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<v.size(); i++) tv.push_back(v[ind[i]]);
~^~~~~~~~~
citymapping.cpp:49:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<v.size(); ) {
~^~~~~~~~~
citymapping.cpp:52:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (i+1<v.size() and d[i] == d[i+1]) {
~~~^~~~~~~~~
citymapping.cpp:56:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (i < v.size()) {
~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |