Pagini recente »
Rating Panciu Fabian Andrei (Fabian)
|
Monitorul de evaluare
|
Cod sursă (job #111272)
|
Diferențe pentru utilizator/petruapostol între reviziile 88 și 49
|
Cod sursă (job #521689)
Cod sursă (job
#521689)
#include <bits/stdc++.h>
using namespace std;
ifstream in("zapada.in");
ofstream out("zapada.out");
int TT[10010];
int get_root(int x)
{
int R = x;
while(R != TT[R]) R = TT[R];
while(TT[x] != x)
{
int y = TT[x];
TT[x] = R;
x = y;
}
return R;
}
void unite(int x, int y)
{
if(x > y) TT[y] = x;
else TT[x] = y;
}
struct bobu
{
int x, y, c;
}G[100010];
bool cmp(bobu x, bobu y)
{
return x.c < y.c;
}
int Sol, n, m, k;
void solve()
{
for(int i = 1;i <= n;i++)
TT[i] = i;
sort(G + 1,G + m + 1, cmp);
for(int i = 1;i <= m;i++)
{
if(get_root(G[i].x) != get_root(G[i].y))
{
Sol += G[i].c;
unite(get_root(G[i].x), get_root(G[i].y));
}
}
out << Sol << '\n';
}
int main()
{
in >> n >> m >> k;
for(int i = 1;i <= m;i++)
in >> G[i].x >> G[i].y >> G[i].c;
solve();
while(k--)
{
m++;
in >> G[m].x >> G[m].y >> G[m].c;
Sol = 0;
solve();
}
return 0;
}