# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
622814 | PoonYaPat | City Mapping (NOI18_citymapping) | C++14 | 8 ms | 8436 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 "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pii;
typedef tuple<int,int,int> t;
int n;
vector<int> v[1001];
vector<t> ans;
ll dis[1001][1001];
ll get(int x, int y) {
if (!dis[x][y]) dis[x][y]=dis[y][x]=get_distance(x,y);
return dis[x][y];
}
void find(int x) {
int r;
ll longest=0;
vector<pii> temp; //dis and node in backbone
vector<int> tree;
for (auto s : v[x]) if (dis[x][s]>longest) longest=dis[x][s], r=s; //find backbone
for (auto s : v[x]) {
if (get(x,s)+get(s,r)==get(x,r)) temp.push_back(pii(get(x,s),s)); //in backbone
else tree.push_back(s);
}
sort(temp.begin(),temp.end());
ans.push_back(t(x,temp[0].second,temp[0].first));
for (int i=1; i<temp.size(); ++i) {
ans.push_back(t(temp[i-1].second,temp[i].second,temp[i].first-temp[i-1].first));
}
for (auto s : tree) {
for (auto b : temp) {
if (dis[x][s]-(dis[x][s]+dis[s][r]-dis[x][r])/2==b.first) {
v[b.second].push_back(s);
dis[b.second][s]=dis[s][b.second]=(dis[x][s]+dis[s][r]-dis[x][r])/2;
break;
}
}
}
for (auto s : temp) if (v[s.second].size()) find(s.second);
}
void find_roads(int N, int Q, int A[], int B[], int W[]) {
n=N;
//find rim
int l;
ll longest=0;
for (int i=1; i<n; ++i) {
if (get(n,i)>longest) {
longest=dis[n][i];
l=i;
}
}
for (int i=1; i<=n; ++i) {
if (i==l) continue;
v[l].push_back(i);
get(i,l);
}
find(l);
for (int i=0; i<ans.size(); ++i) tie(A[i],B[i],W[i])=ans[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... |