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;
struct Edge
{
int a;
int b;
ll cost;
};
bool operator < (Edge f, Edge s)
{
return f.cost < s.cost;
}
void find_roads(int n, int q, int e_a[], int e_b[], int e_w[])
{
vector<int> t(n + 1);
iota(t.begin(), t.end(), 0);
function<int(int)> root = [&] (int a)
{
if (t[a] == a)
{
return a;
}
else
{
return t[a] = root(t[a]);
}
};
auto join = [&] (int a, int b)
{
t[root(a)] = root(b);
};
vector<Edge> edges;
for (int i = 1; i <= n; i++)
{
for (int j = i + 1; j <= n; j++)
{
edges.push_back({i, j, get_distance(i, j)});
}
}
sort(edges.begin(), edges.end());
int top = 0;
for (auto &it : edges)
{
if (root(it.a) != root(it.b))
{
e_a[top] = it.a;
e_b[top] = it.b;
e_w[top] = it.cost;
top++;
assert(top <= n - 1);
join(it.a, it.b);
}
}
assert(top == n - 1);
return;
}
# | 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... |