SDUTOJ 2498 Key Path on AOE (longest path)
Key Path on AOE Time Limit: 1000 MS Memory limit: 65536 K Description
A Directed Graph without loops is called a Directed Graph (DAG.
AOE (Activity On Edge) Network: as the name suggests, an Edge is used to represent the active network. Of course, it is also a DAG. Unlike AOV, the activity is represented on the edge, as shown in:
As shown above, there are 11 Activities (11 edges) and 9 events (9 vertices ). The entire project has only one start point and one completion point. That is, there is only one point with zero inbound (source point) and only one point with zero outbound (sink point ).
Key Path: The longest path length from the start point to the completion point. The path length is the time consumed by the edge activity. As shown in, 1 to 2 to 5 to 7 to 9 are key paths (there are more than one key path. Please output the smallest Lexicographic Order). The sum of weights is 18.
The input contains multiple groups of data. ensure that there are no more than 10 groups, and there is only one source point and sink point. Input a vertex number n (2 <= n <= 10000), edge number m (1 <= m <= 50000), and then input the start point sv, end point ev, weight w (1 <= sv, ev <= n, sv! = Ev, 1 <= w <= 20 ). Data ensures graph connectivity. Output the weights and values of the key paths, and output the paths on the key paths from the source point (if there are multiple paths, output the smallest Lexicographic 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
It is prompted that the key path on the AOE network is to find the longest path, but more is the composition of the longest channel to be obtained.
Therefore, a num [1000]. B is set up to update the next vertex connected to a vertex. Finally, from the source point to the sink point
You can obtain the vertex composed of the longest path through traversal, but this question requires that if there are more than one key path
The lexicographic output was a little simple at the time. When I finished the knock, I handed in the result and WA. I don't know why it was wrong or why.
Where should I change the path? Thanks to Brother Yan for waking up his dream and adding A condition. Thank you, Brother Yan !!! Tears
Full-faced ...... source sample program
#include
#include#include
#include
#include
#include
using namespace std;const int INF = 0;struct node{ int x,y,z;}q[1001000];struct node1{ int a,b;};int n,m;int t;struct node1 num[1100001];void add(int x,int y,int z){ q[t].x = x; q[t].y = y; q[t++].z = z;}void BF(){ for(int i=0;i<=n;i++) { num[i].a = INF; num[i].b = -1; } num[n].a = 0; int flag = 0; for(int i=1;i