# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1099511 | NoMercy | City Mapping (NOI18_citymapping) | C++14 | 10 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 <bits/stdc++.h>
#include "citymapping.h"
using namespace std;
typedef long long ll;
const int MAXN = 1e3 + 100;
vector<int> g[MAXN], del(MAXN, 0);
ll d[MAXN][MAXN];
vector<array<int, 2>> ans;
int sz[MAXN], mx[MAXN];
void dfs (int si) {
sz[si] = 1;
mx[si] = 0;
for (auto v : g[si]) {
if (del[v]) continue;
dfs (v);
sz[si] += sz[v];
if(sz[v] > sz[mx[si]]) mx[si] = v;
}
}
void find_roads (int N, int Q, int A[], int B[], int W[]) {
vector<int> v;
for (int i = 2;i <= N;i ++) {
v.push_back(i);
d[1][i] = get_distance(1, i);
}
sort(v.begin(), v.end(), [](int i, int j){
return d[1][i] < d[1][j];
});
int edg = 0;
for (auto i : v) {
// cout << i << "\n";
for (int j = 0;j <= N + 1;j ++) {
del[j] = 0;
}
int r = 1;
while (true) {
dfs(r);
vector<int> path;
path.push_back(r);
while (mx[path.back()]) {
path.push_back(mx[path.back()]);
}
if (path.size() == 1) {
break;
}
// cout << path.back() << " " << i << "\n";
ll x = d[1][path.back()] + d[1][i] - get_distance(path.back(), i);
x /= 2;
int j = 0;
while (d[1][path[j]] != x) {
j ++;
}
r = path[j];
if (j + 1 < path.size()) {
del[path[j + 1]] = 1;
}
}
A[edg] = r;
B[edg] = i;
W[edg ++] = d[1][i] - d[1][r];
g[r].push_back(i);
}
}
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... |