Submission #1065134

#TimeUsernameProblemLanguageResultExecution timeMemory
1065134LuvidiCity Mapping (NOI18_citymapping)C++17
57 / 100
3 ms1372 KiB
#include <bits/stdc++.h> #include "citymapping.h" using namespace std; #define ll long long #define pb push_back #define fs first #define sc second #define pll pair<ll,ll> int *a,*b,*w,n,cnt; vector<int> ch[1001]; pll r[1001]; void solve(int v){ if(ch[v].empty())return; ll dist[n+1]; pll fr; dist[v]=0; for(int i:ch[v]){ dist[i]=get_distance(i,v); fr=max(fr,{dist[i],i}); } int x=fr.sc; ll dist2[n+1]; vector<pll> pt; r[v]={1e18,1e18}; for(int i:ch[v]){ dist2[i]=get_distance(i,x); ll d=(dist[x]+dist[i]-dist2[i])/2,d2=(dist[i]+dist2[i]-dist[x])/2; if(!d2){ r[i]={1e18,1e18}; pt.pb({dist[i],i}); } } pt.pb({0,v}); sort(pt.begin(),pt.end()); for(int i=1;i<pt.size();i++){ a[cnt]=pt[i-1].sc; b[cnt]=pt[i].sc; w[cnt]=dist[b[cnt]]-dist[a[cnt]]; cnt++; } for(int i:ch[v])if(i!=x){ ll d=(dist[x]+dist[i]-dist2[i])/2,d2=(dist[i]+dist2[i]-dist[x])/2; if(!d2)continue; for(auto[xx,j]:pt){ if(dist[j]==d){ r[j]=min(r[j],{dist[i],i}); } } } for(int i:ch[v])if(i!=x){ ll d=(dist[x]+dist[i]-dist2[i])/2,d2=(dist[i]+dist2[i]-dist[x])/2; if(!d2)continue; for(auto[xx,j]:pt){ if(dist[j]==d){ int k=r[j].sc; if(k!=i)ch[k].pb(i); } } } for(int i=0;i<pt.size();i++){ int j=pt[i].sc; if(r[j].sc<=n){ a[cnt]=j; b[cnt]=r[j].sc; w[cnt]=dist[r[j].sc]-dist[j]; cnt++; solve(r[j].sc); } } } void find_roads(int N, int Q, int A[], int B[], int W[]) { a=A; b=B; w=W; n=N; ll dist[n+1]; pll fr={0,1}; for(int i=1;i<=n;i++){ dist[i]=get_distance(1,i); fr=max(fr,{dist[i],i}); } int x=fr.sc; for(int i=1;i<=n;i++)if(i!=x)ch[x].pb(i); solve(x); }

Compilation message (stderr)

citymapping.cpp: In function 'void solve(int)':
citymapping.cpp:30:6: warning: unused variable 'd' [-Wunused-variable]
   30 |   ll d=(dist[x]+dist[i]-dist2[i])/2,d2=(dist[i]+dist2[i]-dist[x])/2;
      |      ^
citymapping.cpp:38:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for(int i=1;i<pt.size();i++){
      |              ~^~~~~~~~~~
citymapping.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i=0;i<pt.size();i++){
      |              ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...