# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
373438 | luciocf | 시간이 돈 (balkan11_timeismoney) | C++14 | 6 ms | 620 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 <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
struct Edge
{
int u, v, w;
} edge[maxn];
struct DSU
{
int pai[maxn], peso[maxn];
void init(int n)
{
for (int i = 1; i <= n; i++)
pai[i] = i, peso[i] = 1;
}
int Find(int x)
{
if (pai[x] == x) return x;
return pai[x] = Find(pai[x]);
}
void Join(int x, int y)
{
x = Find(x), y = Find(y);
if (x == y) return;
if (peso[x] < peso[y]) swap(x, y);
pai[y] = x, peso[x] += peso[y];
}
} dsu;
bool comp(Edge a, Edge b)
{
return a.w < b.w;
}
int main(void)
{
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++)
{
int u, v, w, w2;
scanf("%d %d %d %d", &u, &v, &w, &w2);
u++, v++;
edge[i] = {u, v, w};
}
sort(edge+1, edge+m+1, comp);
dsu.init(n);
int ans = 0;
vector<pair<int, int>> ans_edge;
for (int i = 1; i <= m; i++)
{
if (dsu.Find(edge[i].u) != dsu.Find(edge[i].v))
{
dsu.Join(edge[i].u, edge[i].v);
ans += edge[i].w;
ans_edge.push_back({edge[i].u, edge[i].v});
}
}
printf("%d %d\n", ans, ans);
for (auto pp: ans_edge)
printf("%d %d\n", pp.first-1, pp.second-1);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |