# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
963481 | sleepntsheep | City Mapping (NOI18_citymapping) | C++17 | 1 ms | 856 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 <vector>
#include <algorithm>
#define N 1005
void find_roads(int n, int q, int A[], int B[], int W[]) {
if (q != 12000)
return;
int root = 1, ad = -1;
int d[N] = { 0 }, e[N] = { 0 };
for (int i = 2; i <= n; ++i)
{
d[i] = get_distance(root, i);
if (ad == -1 || d[i] < d[ad])
ad = i;
}
for (int i = 1; i <= n; ++i)
e[i] = get_distance(ad, i);
std::vector<int> left, right;
left.push_back(ad);
for (int i = 1; i <= n; ++i)
{
if (i == ad || i == root)
continue;
if (e[i] < d[i]) left.push_back(i);
else right.push_back(i);
}
std::sort(left.begin(), left.end(), [&](int i, int j){ return d[i] < d[j] ; });
std::sort(right.begin(), right.end(), [&](int i, int j){ return d[i] < d[j] ; });
for (int pre = root, i = 0; i < left.size(); ++i)
{
A[i] = pre;
B[i] = left[i];
W[i] = d[left[i]] - d[pre];
pre = B[i];
}
for (int pre = root, j = 0, i = left.size(); i < n - 1; ++i, ++j)
{
A[i] = pre;
B[i] = right[j];
W[i] = d[right[j]] - d[pre];
pre = B[i];
}
return;
}
Compilation message (stderr)
# | 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... |