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 y = v[v.size()-1], z = v[0];
vector<lint> a, b, c, d;
lint mxd;
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);
lint mx = 0;
int k;
for (int i=2; i<=n; i++) {
lint now = get_distance(1, i);
if (now > mx) {
mx = now;
k = i;
}
}
swap(v[k-1], v[n-1]);
f(v);
}
Compilation message (stderr)
citymapping.cpp: In function 'void f(std::vector<int>)':
citymapping.cpp:26: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:29: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:35: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:37: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:39: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:42:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<v.size(); ) {
~^~~~~~~~~
citymapping.cpp:45:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (i+1<v.size() and d[i] == d[i+1]) {
~~~^~~~~~~~~
citymapping.cpp:49:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (i < v.size()) {
~~^~~~~~~~~~
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:76:13: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
swap(v[k-1], v[n-1]);
~^~
# | 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... |