# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
836242 | unnick | City Mapping (NOI18_citymapping) | C++14 | 0 ms | 0 KiB |
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 <algorithm>
#include <numeric>
#include <vector>
using namespace std;
#define ll long long
void find_roads(int N, int Q, int A[], int B[], int W[]) {
if (Q <= 12000) {
int start;
{
ll maxd = 0;
for (int i = 2; i <= N; i++) {
ll d = get_distance(1, i);
if (d > maxd) {
maxd = d;
start = i;
}
}
}
// cout << start << "\n";
vector<ll> dists(N);
dists[start-1] = 0;
vector<int> ids(N);
iota(ids.begin(), ids.end(), 0);
for (int i = 1; i <= N; i++) {
if (i == start) continue;
dists[i-1] = get_distance(start,i);
}
sort(ids.begin(), ids.end(), [&](int a, int b) {
return dists[a] < dists[b];
});
for (int i = 0; i < N-1; i++) {
A[i] = ids[i]+1;
B[i] = ids[i+1]+1;
W[i] = dists[ids[i+1]] - dists[ids[i]];
}
} else {
int k = 0;
for (int i = 1; i <= N; i++) {
for (j = i+1; j <= N; j++) {
if (get_distance(i,j) == 1) {
A[k] = i;
B[k] = j;
W[k++] = 1;
}
}
}
}
}