# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
550005 | AKiko | City Mapping (NOI18_citymapping) | C++14 | 116 ms | 8900 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 <bits/stdc++.h>
#define pii pair<int, int>
#define ll long long
#define pb push_back
#define ss second
#define ff first
using namespace std;
vector<int> p(1e3 + 1);
int find(int x) {
if(x == p[x]) return x;
return p[x] = find(p[x]);
}
vector<pair<ll, pii> > mst(int N) {
vector<pair<ll, pii> > path, res;
for(int i = 1; i <= N; i++) {
for(int j = i + 1; j <= N; j++) {
ll ans = get_distance(i, j);
path.pb({ans, {i, j}});
}
}
sort(path.begin(), path.end());
iota(p.begin(), p.end(), 0);
for(auto el : path) {
int a = el.ss.ff, b = el.ss.ss;
ll c = el.ff;
int ap = find(a), bp = find(b);
if(ap == bp) continue;
p[bp] = ap;
res.pb(el);
}
return res;
}
void find_roads(int N, int Q, int A[], int B[], int W[]) {
vector<pair<ll, pii> > paths = mst(N);
for(int i = 0; i < paths.size(); i++) {
A[i] = paths[i].ss.ff;
B[i] = paths[i].ss.ss;
W[i] = paths[i].ff;
}
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... |