一、算法分析
这道题让笔者想起了通往奥格瑞玛的道路这道题,可以说是有异曲同工之妙了。首先题目明确说明了,求最大值最小。一般这样的就与二分答案有关,于是我们记录下来每条边的长度,答案一定是这些长度中的一个,然后将各边的长度排序,二分答案就行了(相当于套一个二分答案的板子和一个dijkstra的板子)。细节处理在代码注释上。
当然本题还有并查集等其它解法,这个随后补上。
二、代码及注释
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#define ll long long
using namespace std;
const int maxn=1000005;
const int inf=0x3f3f3f3f;
ll d[maxn];
bool done[maxn];
int n,m;
struct edge{
int from;
int to;
int dist;
edge(int u,int v,int d):from(u),to(v),dist(d){
}
edge():from(0),to(0),dist(0){
}
};
vector<edge> edges;
vector<edge> edges2; //check要改边,所以要备份
vector<int> mp[maxn];
vector<int> mp2[maxn];
void addedge(int from,int to,int dist){
edges.push_