http://poj.org/problem?id=3522 Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5666   Accepted: 2965 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is a…
kruskal思想,排序后暴力枚举从任意边开始能够组成的最小生成树 #include <cstdio> #include <algorithm> using namespace std; const int maxn = 101; const int maxe = maxn * maxn / 2; struct edge{ int f,t,c; bool operator <(edge e2)const { return c<e2.c; } }e[maxe]; int…
Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 9546   Accepted: 5076 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is an ordered pair (V, E), where V …
Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7102   Accepted: 3761 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is an ordered pair (V, E), where V …
Slim Span Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3522 Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is an ordered pair (V, E), where V is a se…
题目链接:http://poj.org/problem?id=3522 Time Limit: 5000MS Memory Limit: 65536K Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is an ordered pair (V, E), where V is a set of verti…
题目链接http://poj.org/problem?id=3522 kruskal+并查集,注意特殊情况比如1,0 .0,1.1,1 #include<cstdio> #include<iostream> #include<algorithm> #include<climits> using namespace std; #define MAXN 5005 struct edge{ int u,v,cost; }; int comp(const edge&…
http://poj.org/problem?id=3522 一开始做这个题的时候,以为复杂度最多是O(m)左右,然后一直不会.最后居然用了一个近似O(m^2)的62ms过了. 一开始想到排序,然后扫一个长度n - 1区间,要快速判定这个区间能否构成MST,一直都想不到优秀的算法,然后干脆暴力了. 两种方法,1.dfs,删边容易,标记一下就好,但是这是不行的,删边确实容易,但是dfs的时候多次访问无用的边,所以TLE了. 2.并查集,这个复杂度是O(n)的,能AC,但是我的思路还是有一点bug,…
题意: 求出最小生成树中最大边与最小边差距的最小值. 分析: 排序,枚举最小边, 用最小边构造最小生成树, 没法构造了就退出 #include <stdio.h> #include <string.h> #include <iostream> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <se…
题意 求生成树的最长边与最短边的差值的最小值 题解 最小生成树保证每一条边最小,就只要枚举最小边开始,跑最小生成树,最后一个值便是最大值 在枚举最小边同时维护差值最小,不断更新最小值. C++代码 /** /*@author Victor /*language C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<…