answer
So xy <= z x represents a large maximum ratio y z.
If <= k1, cb <= k2 , ca <= k3 ba, ca then up to how much? Obviously it should be equal to min (k1 + k2, k3) . FIG represented by the following diagram (FIG ugly Wuguai not good)
C ++ heap optimized code
// front chain to FIG StarRam + Dijkstra stack optimized #include <the iostream> #include <cstdio> #include <Queue> #include <CString> the using namespace STD; const int MAX = 100005 ; const int MAXN = 400009 ; const int INF = 0x3f3f3f3f ; int head [MAX], CNT = 0 ; int T, n-, A, B, len; int dist [MAX]; BOOL VIS [MAX]; struct Edge { // chain before to star int next,val,to; }Edge[MAXN]; inline void add(int u,int v,int w) { Edge[cnt].to=v; Edge[cnt].val=w; Edge[cnt].next=head[u]; head[u]=cnt++; } struct node { int POS, dist; // position and distance from the point of node () {} node(int p,int d) { pos=p; dist=d; } bool operator < (const node &rhs)const //重载 < { return dist>rhs.dist; } }; void Dij(int start) { priority_queue<node>que; for(int i=1;i<=t;i++) { dist[i]=INF; view [i] = false ; } dist[start]=0; que.push(node(start,0)); while(!que.empty()) { TEMP Node = que.top (); // priority queue elements and the minimum value of dist led array que.pop (); int V = temp.pos; // filter minimum value IF (VIS [V]) Continue ; // determines whether minimum is found, it is skipped VIS [V] = to true ; for ( int I = head [V]; I = -! . 1 ; Edge I = [I] .next) // with the minimum point of the arc from the trailing edge of updates { int to = Edge [I] .to; IF (dist [to]> dist [V] + Edge [I] .val) { dist[to]=dist[v]+Edge[i].val; que.push(node(to,dist[to])); } } } } int main () { while(scanf("%d%d",&t,&n)!=EOF) { memset(head,-1,sizeof(head)); for(int i=0;i<n;i++) { scanf("%d%d%d",&a,&b,&len); add(a,b,len); //add(b,a,len); } Against ( 1 ); printf("%d\n",dist[t]); } return 0; }
C ++ pairing heap optimization
#include <bits/stdc++.h> #include<ext/pb_ds/priority_queue.hpp> using namespace std; using namespace __gnu_pbds; typedef pair<int,int> pii; typedef __gnu_pbds::priority_queue<pii,greater<pii>,pairing_heap_tag> Heap; const int maxn=1e5+10; const int INF=0x3f3f3f3f; int n,m,s; struct Edge{ int u,v,w; Edge(int _u=0,int _v=0,int _w=0){u=_u,v=_v,w=_w;} }; vector<Edge> E; vector<int> G[maxn]; void addedge(int u,int v,int w) { E.push_back(Edge(u,v,w)); G[u].push_back(E.size()-1); } int d[maxn]; void dijkstra() { memset(d,0x3f,sizeof(d)); Heap Q; Heap::point_iterator id[maxn]; d[s]=0; id[s]=Q.push(make_pair(d[s],s)); while(!Q.empty()) { int u=Q.top().second; Q.pop(); for(int i=0;i<G[u].size();i++) { Edge &e=E[G[u][i]]; int v=e.v; if(d[v]>d[u]+e.w) { d[v]=d[u]+e.w; if(id[v]!=0) Q.modify(id[v],make_pair(d[v],v)); else id[v]=Q.push(make_pair(d[v],v)); } } } } int main () { while(~scanf("%d%d",&n,&m)){ s = 1;//起点 //memset(d,0,sizeof d); memset(G,0,sizeof G); for(int i=1;i<=m;i++) { int u,v,w; scanf("%d%d%d",&u,&v,&w); addedge(u,v,w); } dijkstra(); //for(int i=1;i<=n;i++) printf("%d%s",d[i],((i==n)?"\n":" ")); printf("%d\n",d[n]); } }