Submission #538956

#TimeUsernameProblemLanguageResultExecution timeMemory
538956ac2huCity Mapping (NOI18_citymapping)C++14
9 / 100
187 ms63100 KiB
#include<bits/stdc++.h> #include "citymapping.h" using namespace std; const int N = 1e3 + 1; long long dist[N][N]; int n; int par[N]; long long gd(int x,int y){ if(dist[x][y] != -1) return dist[x][y]; long long temp = get_distance(x + 1, y + 1); dist[x][y] = temp; dist[y][x] = temp; return temp; } bool inpath(int a,int b, int c){// check if c lies on a - b return gd(a, c) + gd(c, b) == gd(a, b); } void dfs(int r,int p, set<int> temp){ par[r] = p; if(temp.size() == 0) return; vector<pair<long long,int>> tt; for(int j : temp){ tt.push_back({gd(r, j), j}); } sort(tt.begin(),tt.end()); while(tt.size() > 3) tt.pop_back(); while(tt.size() > 1 && inpath(r, tt[1].second, tt[0].second)){ tt.erase(tt.begin() + 1); } for(int al = 0;al<2;al++){ if(tt.size() > 2 && inpath(r, tt[2].second, tt[al].second)){ tt.erase(tt.begin() + 2); } } for(int al = 0;al<tt.size();al++){ temp.erase(temp.find(tt[al].second)); } // Only children are in tt vector<set<int>> hold(tt.size()); for(auto e : temp){ for(int i = 0;i<tt.size();i++){ if(inpath(r, e , tt[i].second)){ hold[i].insert(e); break; } } } for(int i = 0;i<tt.size();i++){ dfs(tt[i].second, r , hold[i]); } } void find_roads(int N, int Q, int A[], int B[], int W[]) { n = N; for(int i = 0;i<N;i++){ for(int j = 0;j<N;j++){ dist[i][j] = -1; } } int r = 0; set<int> temp; for(int i = 0;i<n;i++){ if(r == i)continue; temp.insert(i); } // vector<array<int,3>> edges; dfs(r, -1, temp); vector<array<int,3>> edges; int p1 = 0; for(int i = 0;i<n;i++){ if(i != r){ edges.push_back({i + 1, par[i] + 1, (int)gd(i,par[i])}); } } for(int i = 0;i<n-1;i++){ A[i] = edges[i][0], B[i] = edges[i][1], W[i] = edges[i][2]; } return; }

Compilation message (stderr)

citymapping.cpp: In function 'void dfs(int, int, std::set<int>)':
citymapping.cpp:37:19: 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]
   37 |  for(int al = 0;al<tt.size();al++){
      |                 ~~^~~~~~~~~~
citymapping.cpp:43:18: 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]
   43 |   for(int i = 0;i<tt.size();i++){
      |                 ~^~~~~~~~~~
citymapping.cpp:50:17: 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]
   50 |  for(int i = 0;i<tt.size();i++){
      |                ~^~~~~~~~~~
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:70:6: warning: unused variable 'p1' [-Wunused-variable]
   70 |  int p1 = 0;
      |      ^~
#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...