This problem can not understand the topic AH ~ Reference Http://blog.csdn.net/qq_26437925/article/details/49420089?locationNum=6&fps=1
Let's put it on first.
#include"iostream"#include"Vector"using namespacestd;intin_degree[101];/*the entry of each node of the recording graph*/structNode {inte; intCost ;}; Vector<node>v[101];intearly[101];intN, M;BOOLToplogicsort () {intStart =-1; for(inti =0; I < n; i++) { if(In_degree[i] = =0) {Start=i; Break; } } if(Start = =-1) {/*no entry for 0 points*/ return false; } Early[start]=0; intsum =0; intnum =0; intNEWP =start; while(num! = N-1) { intLen = V[newp].size ();/*out of*/ for(inti =0; i < Len; i++) { intE =V[NEWP][I].E; intCost =V[newp][i].cost; In_degree[e]--; if(EARLY[NEWP] + cost >Early[e]) {Early[e]= Early[newp] +Cost ; }} IN_DEGREE[NEWP]= -1;/*Delete the node*/NEWP= -1; for(inti =0; I < n; i++) { if(In_degree[i] = =0) {NEWP=i; Break; } } if(NEWP = =-1) return false; if(EARLY[NEWP] >sum) sum=EARLY[NEWP]; Num++; } cout<< sum <<Endl; return true;}intMain () {node node; CIN>> N >>m; for(inti =0; I < n; i++) {In_degree[i]=0; Early[i]=0; } while(m--) { intS, E, l; CIN>> s >> e >>l; NODE.E=e; Node.cost=BL; V[s].push_back (node); In_degree[e]++; } if(!Toplogicsort ()) cout<<"Impossible"<<Endl;}
PTA 5-12 how Long Does It take (25 points)