# 216. The minimum cost Shortest

As if not earlier, ah this time. . . Well anyway, nothing to do, but also to chat with people, just still owe so much, you can write to write some of it, trained, trained, trained,

Ultimate questions face magic technique lalala (fool bloggers)

This question it is basically a bare shortest, although the teacher let us do it with dijkstra, however. . Like spfa etc. can also be had, of course, there is a better way to use teacher

 1 #include<set>
 2 #include<map>
 3 #include<list>
 4 #include<queue>
 5 #include<stack>
 6 #include<string>
 7 #include<cmath>
 8 #include<ctime>
 9 #include<vector>
10 #include<bitset>
11 #include<memory>
12 #include<utility>
13 #include<cstdio>
14 #include<sstream>
15 #include<iostream>
16 #include<cstdlib>
17 #include<cstring>
18 #include<algorithm>
19 using namespace std;
20 
21 int n,m,s,t,tot;
22 int next[1000005],head[1000005],to[1000005],cost[1000005],value[1000005],dis[1000005],ans_c[1000005];
23 struct node{
24     int id,d,v;
25 }a[1000005];
26 bool operator > (const node a,const node b){//重构
27     return AD> BD;
 28  }
 29 The priority_queue <Node, Vector <Node>, Greater <Node>> Q; // rootlets heap stack optimized
 30  
31 is  void the Add ( int U, int V, int W, int P) { // star prior to the chain
 32      Next [TOT ++] = head [U];
 33 is      head [U] = TOT;
 34 is      to [TOT] = V;
 35      cost [TOT] = W;
 36      value [TOT] = P;
 37 [      return ;
 38 is  }
 39  void Dijkstra () {// shortest
 40     memset(dis,0x3f,sizeof(dis));
41     memset(ans_c,0x3f,sizeof(ans_c));
42     dis[s]=0;
43     ans_c[s]=0;
44     Q.push((node){s,0,0});
45     while(!Q.empty()){
46         node x=Q.top(); 
47         Q.pop();
48         for(int i=head[x.id];i;i=next[i])
49             if(x.d cost + [I] <DIS [to [I]] || (x.d cost + [I] == DIS [to [I]] && ans_c [to [I]]> + x.v value [ i])) {// if the path means is less than or equal to the recorded path costs less but
 50                  DIS [to [I]] = + x.d cost [I];
 51 is                  ans_c [to [I]] = + x.v value [I];
 52 is                  Q.push ((Node) {to [I], DIS [to [I]], ans_c [to [I]]});
 53 is              }
 54 is      }
 55      return ;
 56 is  }
 57 is  int main () {
 58      the while ( . 1 ) {
 59          Scanf ( " % D% D " , & n-, & m);
 60          IF (n-== 0m == && 0 ) {// End condition
 61 is              BREAK ;
 62 is          }
 63 is          Memset (head, 0 , the sizeof (head));
 64          the while (! Q.empty ()) {Q.pop ();}
 65          for ( int I = . 1 ; I <= m; I ++ ) {
 66              int U, V, W, C;
 67              Scanf ( " % D% D% D% D " , & U, & V, & W, & C);
 68              the Add (U , v, w, c); // since undirected graph, so the duplex path
 69              the Add (V, U, W, C);
 70          }
 71 is         scanf("%d%d",&s,&t);
72         memset(dis,0,sizeof(dis));
73         memset(ans_c,0,sizeof(ans_c));
74         dijkstra();
75         printf("%d %d\n",dis[t],ans_c[t]);
76     }
77     return 0;
78 }

This problem in the engine room knocked for a long time to say. . AC code is complete and there is no difference. . Heavy hit home again, and then pass by? ? ? Inexplicable. .

Guess you like

Origin www.cnblogs.com/hahaha2124652975/p/11124122.html