有向最小树形图,贴个模板
#include <stdio.h>
#include <string.h>
#include <math.h>
#define V 128
#define E 10240
#define typec double // type of res
const typec inf = 0x3f3f3f3f; // max of res
typec res, dis[V];
int to[V], cp[V], tag[V];
struct Edge
{
int u, v;
typec c;
Edge(int a = 0,int b = 0,double cc = 0.0)
{
u = a;
v = b;
c = cc;
}
} eg[E];
int iroot(int i){
if (cp[i] == i) return i;
return cp[i] = iroot(cp[i]);
}
int dirtree(int root, int nv, int ne) // root: 树根
{ // vertex: 0 ~ n-1
int i, j, k, circle = 0;
memset(tag, -1, sizeof(tag));
memset(to, -1, sizeof(to));
for (i = 0; i < nv; ++i) dis[i] &