Pagini recente »
Istoria paginii utilizator/batolit
|
Istoria paginii utilizator/guzudaniel
|
Istoria paginii utilizator/roxana_3
|
Istoria paginii utilizator/catalina2603
|
Cod sursă (job #357024)
Cod sursă (job
#357024)
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 10005;
const int MMAX = 100005;
int big;
bitset < NMAX > Good;
short Father[NMAX];
int countt;
long long Answer = 0;
set < pair < int , pair < short , short > > > S;
int N,M,K;
inline void ScanData()
{
scanf("%d%d%d", &N ,&M , &K);
for ( int i = 1; i <= M ; ++i)
{
short x,y;
int price;
scanf("%hd%hd%d", &x , &y , &price);
S.insert(make_pair(price,make_pair(x,y)));
}
}
inline void Unite(int x, int y)
{
Father[y] = x;
}
inline int Root(int Node)
{
int R = Node;
while(Father[R] > 0)
R = Father[R];
while(Father[Node] > 0)
{
Father[Node] = R;
Node = R;
}
return Node;
}
inline void APM()
{
memset(Father , 0 , sizeof Father);
Answer = 0;
big = 0;
multiset < int > :: iterator it;
for ( auto it : S)
{
int Node1 = it.second.first;
int Node2 = it.second.second;;
int Price = it.first;
//cout << Node1 <<" " << Node2 <<" " << Price <<"\n";
int Root1 = Root(Node1);
int Root2 = Root(Node2);
if(Price == SHRT_MAX)
break;
if( Root1 != Root2 && Price != SHRT_MAX)
{
Unite(Root1,Root2);
Answer+=Price;
if(it.first > big)
big = it.first;
}
else {
it.first = SHRT_MAX;
//cout << it.first <<"\n";
}
}
//cout << endl;
printf("%lld\n" , Answer);
}
int main()
{
freopen("zapada.in" , "r" ,stdin);
freopen("zapada.out" , "w", stdout);
ScanData();
APM();
for ( int i = 1 ; i <= K ; ++i)
{
short x,y;
int price;
scanf("%hd%hd%d", &x , &y , &price);
if( price > big)
printf("%lld\n" , Answer);
//int nufac=0;
else
{
S.insert(make_pair(price,make_pair(x,y)));
APM();
}
}
return 0;
}