Sdutoj 2498 AoE critical path on the web Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^ Title Description
A non-circular, forward graph is called a non-circular graph (Directed acyclic graph), referred to as the DAG graph.
AOE (activity on edge) network: As the name implies, use the edge to represent the active network, of course, it is also a DAG. Unlike AOV, activities are represented on the edge, as shown in:
as shown above, there are 11 activities (11 edges),9 events (9 vertices). The whole project has only one start point and one completion point. That is, there is only one point with zero degrees (source) and only one point with zero out (meeting point).
Critical Path: Is the length of the longest path from the start point to the completion point. The length of the path is the time spent on the edge. As shown,1 to 2 to 5 to 7 to 9 is the critical path (more than one key path, output dictionary order of the smallest), the weight of the value of 18.
InputThere are multiple sets of data, guaranteed to be no more than 10 groups, guaranteed to have only one source and sink point. Enter a top point N (2<=n<=10000), number of sides m (1<=m <=50000), next m line, input start SV, end ev, weight value w (1<=sv, Ev<=n,sv! = ev,1<=w <=20). Data Assurance diagram connectivity. OutputThe weight of the critical path and the path on the critical path from the source point (if there are more than one, output the smallest dictionary order). Sample input
9 111 2 61 3 41 4 52 5 13 5 14 6 25 7 95 8 76 8 48 9 47 9 2
Sample output
181 22 55) 77 9
1 /*Remember, the output path is the smallest dictionary order, to reverse the edge, can be taken to the dictionary order*/2 /*The essence of this topic is to reverse the side, not the positive, we can explain this: the shortest dictionary order of the path is when we go to a point, to the next step, choose the smallest number, which is the dictionary, but the shortest-circuit update process, (dis[edge[l].v]== DIS[X]+EDGE[L].W&&X<PRE[EDGE[L].V], obviously the number of points before the point is small, so that it can be taken out, it may not be the dictionary order3 */4#include <queue>5 #defineN 100106#include <iostream>7 #defineM 500108 using namespacestd;9#include <cstdio>Ten#include <cstring> One structedge{ A intv,last,w; - }edge[m]; - intHead[n],ans[n],pre[n],n,m,dis[n],indu[n],chudu[n]; the BOOLInque[n]; - voidAdd_edge (intUintVintWintk) - { -edge[k].v=v;edge[k].w=W; +edge[k].last=Head[u]; -head[u]=K; + } A voidinput () at { - intu,v,w; - for(intI=1; i<=m;++i) - { -scanf"%d%d%d",&u,&v,&W); - Add_edge (v,u,w,i); inindu[u]++;chudu[v]++; - } to } + voidSPFA (intUintv) - { thequeue<int>que; * que.push (u); $pre[u]=0;d is[u]=0;Panax Notoginsenginque[u]=true; - while(!que.empty ()) the { + intx=Que.front (); A Que.pop (); theinque[x]=false; + for(intL=head[x];l;l=edge[l].last) - { $ if(dis[edge[l].v]<dis[x]+edge[l].w| | (dis[edge[l].v]==dis[x]+edge[l].w&&x<PRE[EDGE[L].V])) $ { -dis[edge[l].v]=dis[x]+EDGE[L].W; -pre[edge[l].v]=x; the if(!INQUE[EDGE[L].V]) - {Wuyiinque[edge[l].v]=true; the Que.push (EDGE[L].V); - } Wu } - } About } $ } - voidPrintintUintv) - { -printf"%d\n", Dis[v]); A intt=v; +ans[++ans[0]]=v; the while(pre[t]!=0) - { $ans[++ans[0]]=Pre[t]; thet=Pre[t]; the } the for(intI=2; i<=ans[0];++i) theprintf"%d%d\n", ans[i-1],ans[i]); - } in intMain () the { the while(SCANF ("%d%d", &n,&m) = =2) About { thememset (DIS,0,sizeof(DIS)); theMemset (Edge,0,sizeof(Edge)); theMemset (Head,0,sizeof(head)); +memset (Indu,0,sizeof(Indu)); -memset (Chudu,0,sizeof(Chudu)); thememset (PRE,127,sizeof(pre));Bayimemset (ans,0,sizeof(ans)); thememset (Inque,false,sizeof(Inque)); the input (); - intu,v; - for(intI=1; i<=n;++i) the { the if(!indu[i]) u=i; the if(!chudu[i]) v=i; the } - SPFA (u,v); the print (u,v); the } the return 0;94}
Critical Path Sdutoj 2498