제출 #93514

#제출 시각아이디문제언어결과실행 시간메모리
93514adminCity Mapping (NOI18_citymapping)C++17
25 / 100
39 ms508 KiB
#include "citymapping.h" #include <bits/stdc++.h> using namespace std; using lint = long long; using pil = pair<int, long long>; void find_roads(int N, int Q, int A[], int B[], int W[]) { const int ROOT = 1; vector<lint> dist_to_root(N+1); for(int u = 1; u <= N; u++) { if(u != ROOT) dist_to_root[u] = get_distance(ROOT, u); } vector<int> internal(N); iota(internal.begin(), internal.end(), 1); sort(internal.begin(), internal.end(), [&](const int &p, const int &q) { return dist_to_root[p] < dist_to_root[q]; }); int e = 0; for(unsigned i = 1; i < internal.size(); i++) { int u = internal[i]; int v = -1; lint d = 1e18; for(unsigned j = 0; j < i; j++) { int p = internal[j]; lint c = (j == 0) ? dist_to_root[u] : get_distance(u, p); if(v == -1 || d > c) { d = c; v = p; } } A[e] = u; B[e] = v; W[e] = d; e += 1; } }
#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...