For illustration. Calculates the shortest random sub-ans1. and delete edges. Free to be able to get maximum and short-circuiting between the maximum points ans2 if these two do not communicate. As the shortest distance between two points L.
The first idea is to enumerate each edge and then run n the shortest time. However, this complexity is 1000*1000*100*log (100), too large: In fact, at a fixed starting point, the shortest time to find the unit. At the same time can find the shortest single source tree, only the deletion of the edge in the tree. The shortest path of the source point to any point will change, so in each run single source the most short-circuit, only need to enumerate the tree n-1 edge can be. Add up to delete each edge, in the case of the current source point. The sum of the shortest distance is added, and the last enumeration is able to find the one with the most added amount.
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <queue > #include <cstring> #include <vector>using namespace Std;typedef long Long ll;const ll inf= (1ll<<61 ); ll Cost[2020];int N,m;ll l;struct heapnode{ll D; int u; BOOL operator< (const heapnode& RHS) Const {return d>rhs.d; } heapnode () {} heapnode (ll x,int y) {d=x; U=y; }};struct edge{int u,v; ll W; BOOL OK; Edge () {} edge (int x,int y,ll z) {u=x; V=y; W=z; Ok=true; }};const int maxn=105;struct dij{int n,m; Vector<edge> edges; Vector<int> G[MAXN]; BOOL DONE[MAXN]; ll D[MAXN]; int P[MAXN]; void init (int n) {this->n=n; for (int i=0; i<=n; i++) {g[i].clear (); } edges.clear (); } void Addedge (int x,int y,ll z) {edges.push_back (Edge (x, Y, z)); m=Edges.size (); G[x].push_back (m-1); } void Dijkstra (int s) {priority_queue
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
la4080 Warfare and Logistics list + shortest