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;
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,l;
ll longest=0;
vector<pii> temp; //dis and node in backbone
vector<int> tree;
v[x].push_back(x);
for (auto s : v[x]) if (get(x,s)>longest) longest=get(x,s), r=s;
longest=0;
for (auto s : v[x]) if (get(r,s)>longest) longest=get(r,s), l=s;
for (auto s : v[x]) {
if (r==s) continue;
if (get(r,s)+get(s,l)==get(r,l)) temp.push_back(pii(get(r,s),s));
else tree.push_back(s);
}
sort(temp.begin(),temp.end());
ans.push_back(t(r,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));
}
v[x].clear();
for (auto s : tree) {
for (auto b : temp) {
if (dis[r][s]-(dis[r][s]+dis[s][l]-dis[r][l])/2==b.first) {
v[b.second].push_back(s);
dis[b.second][s]=dis[s][b.second]=(dis[r][s]+dis[s][l]-dis[r][l])/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;
for (int i=2; i<=n; ++i) v[1].push_back(i);
find(1);
for (int i=0; i<ans.size(); ++i) tie(A[i],B[i],W[i])=ans[i];
return;
}
Compilation message (stderr)
citymapping.cpp: In function 'void find(int)':
citymapping.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int i=1; i<temp.size(); ++i) {
| ~^~~~~~~~~~~~
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:60:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int i=0; i<ans.size(); ++i) tie(A[i],B[i],W[i])=ans[i];
| ~^~~~~~~~~~~
citymapping.cpp: In function 'void find(int)':
citymapping.cpp:44:56: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
44 | if (dis[r][s]-(dis[r][s]+dis[s][l]-dis[r][l])/2==b.first) {
| ~~~~~~~~^
citymapping.cpp:44:56: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | 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... |