对于一个给定的连通的无向图 G = (V, E),希望找到一个无回路的子集 T,T 是 E 的子集,它连接了所有的顶点,且其权值之和为最小. 因为 T 无回路且连接所有的顶点,所以它必然是一棵树,称为生成树(Spanning Tree),因为它生成了图 G.显然,由于树 T 连接了所有的顶点,所以树 T 有 V - 1 条边.一张图 G 可以有很多棵生成树,而把确定权值最小的树 T 的问题称为最小生成树问题(Minimum Spanning Tree).术语 "最小生成树" 实际上是
Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of a truck. The code is simply a string of ex
并查集+kruskal==>MST 效率很低 #include <iostream> using namespace std; #define MAX 105 //自己设置最大值 // father[x]表示x的父节点 int father[MAX]; // rank[x]表示x的秩 int rank[MAX]; typedef struct { int i,j; int distance; } E; E edges[MAX*MAX]; // 初始化 void Make_Set(int
#include <stdio.h> #include <stdlib.h> #define MAX 100 int N, M; struct Edge { int u,v; int weight; } edge[MAX]; int vertexs[MAX]; int parents[MAX]; int edge_cmp(const void* a, const void* b) { return ((struct Edge*)a)->weight - ((struct Ed
题目链接:http://poj.org/problem?id=1789 Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of a truck. The code
题目链接: 传送门 find the most comfortable road Time Limit: 1000MS Memory Limit: 32768 K Description XX星有许多城市,城市之间通过一种奇怪的高速公路SARS(Super Air Roam Structure---超级空中漫游结构)进行交流,每条SARS都对行驶在上面的Flycar限制了固定的Speed,同时XX星人对 Flycar的"舒适度"有特殊要求,即乘坐过程中最高速度与最低速度的差越小