The key point is that, for a single source of the shortest path, if the most short-circuit tree edge is not changed, then the most short-circuit must not change,
So as long as the enumeration deletes the edges on the shortest path tree. The complexity of the time will be over.
Blind to the real deletion, the result of t ...
#include <bits/stdc++.h>using namespacestd;Const intMAXN =102, MAXM =2002;intHEAD[MAXN], TO[MAXM], nxt[maxm],wei[maxm],ecnt;intDELTA[MAXM];voidAddedge (intUintVintW) {to[ecnt]=v; NXT[ECNT]=Head[u]; WEI[ECNT]=W; Head[u]= ecnt++;} typedef pair<int,int>Node;#defineFi first#defineSe SecondintD[maxn],pa[maxn];typedefLong Longll;voidDijkstraintNintSintLBOOLFlagintE1,intE2)//E1 E2 side should be ignored{priority_queue<Node,vector<Node>,greater<Node> >Q; Fill (d,d+n,l); D[s]=0; Q.push (Node (0, s)); Pa[s] =-1; while(Q.size ()) {Node x=q.top (); Q.pop (); intU =x.se; if(x.fi! = D[u])Continue; for(inti = Head[u]; ~i; i = Nxt[i])if(I!=e1 && i!=E2) { intv =To[i]; if(D[v] > d[u]+Wei[i]) {D[v]= d[u]+Wei[i]; if(flag) Pa[v] = i;//number of incoming edgesQ.push (Node (d[v],v)); }}}}ll cal (intN) {LL ret=0; for(inti =0; I < n; i++) {ret+=D[i]; } returnret;}voidinit () {memset (head,-1,sizeof(head)); ECNT=0; memset (Delta,0,sizeof(delta));}intMain () {//freopen ("In.txt", "R", stdin); intn,m,l; while(~SCANF ("%d%d%d",&n,&m,&m)) {init (); while(m--){ intU,v,w; scanf"%d%d%d",&u,&v,&W); Addedge (--u,--v,w); Addedge (V,U,W); } ll ans1=0; Vector<int>edges; for(intU =0; U < n; u++) {Dijkstra (n,u,l,true,-1,-1); ll T=cal (n); Ans1+=T; for(inti =0; I < n; i++){ if(~Pa[i]) {Dijkstra (n,u,l,false, pa[i],pa[i]^1); intEid = pa[i]& (~1); if(!Delta[eid]) edges.push_back (EID); Delta[eid]+ = CAL (n)-T; } } } intMaxdelta =0; for(inti =0; I < (int) Edges.size (); i++) {Maxdelta=Max (Maxdelta,delta[edges[i]]); } printf ("%lld%lld\n", ans1,ans1+Maxdelta); } return 0;}
Uvalive 4080 Warfare and Logistics