dsfghsdfhdgsdf

#include<stdio.h>
#include<algorithm>
using namespace std;
struct edge
{
int u , v , w ;
}e[10000 * 2];
int p[110] , n , built , mid ;

void init ()
{
for (int i = 0 ; i <= 110 ; i++)
p[i] = i ;
}

int find (int x)
{
return x == p[x] ? x : find(p[x]) ;
}

bool cmp (edge a , edge b)
{
return a.w < b.w ;
}

void kruskal (int m)
{
init () ;
sort (e + 1 , e + m) ;
int ans = 0 , x , y ;
for (int i = 1 ; i < m ; i++) {
x = find (e[i].u) ;
y = find (e[i].v) ;
if ( x != y ) {
ans += e[i].w ;
p[x] = y ;
}
}
printf ("%d\n" , ans ) ;
}

void binary (int x , int y , int l , int r)
{
if (l >= r)
return;
mid = l + r >> 1 ;
binary (x , y , l , mid ) ;
binary (x , y , mid + 1 , r ) ;
if ( e[mid].u == x && e[mid].v == y )
return;
}

int main ()
{
// freopen ("a.txt" , "r" , stdin ) ;
int m ;
int x , y ,els;
int k ;//已建的边
while (~ scanf ("%d" , &n) ) {
m = 1 ;
for (int i = 1 ; i <= n ; i++ ) {
for (int j = 1 ; j <= i ; j++ ) {
scanf ("%d" , &els) ;
}
for (int j = i + 1 ; j <= n ; j++ ) {
e[m].u = i ;
e[m].v = j ;
scanf ("%d" , &e[m].w ) ;
m++ ;
}
}
scanf ("%d" , &built ) ;

/* for (int i = 0 ; i < built ; i++) {
scanf ("%d%d" , &x , &y ) ;
binary (x , y , 1 , m) ;
e[mid].w = 0 ;
}
kruskal (m) ;*/
}
return 0 ;
}

时间: 2024-09-29 10:49:25

dsfghsdfhdgsdf的相关文章