#include <iostream> #include <stack> #include <cstring> #include <string> #include < algorithm>using namespace std; #define MAXN int MAP[MAXN][MAXN]; int IN_COUT[MAXN]; inte_time[maxn]; int ARRY[MAXN] ; int N, E, n_s = 1, sum; int max (int x, int y) {return x > y x:y;} void Get_et () {int I,j;stack<int> s; for (i = 0; i < n; i++) {if (!in_cout[i]) s.push (i);//Get starting point}int Sep = 0; while (!s.empty ()) {int flag = S.top (); S.pop (); arry[sep++] = flag; for (i = 0; i < n; i++) {if (Map[flag][i]) {//points to be connected to flag, in degrees minus, and to determine if the bar Pieces into S. In_cout[i]--;if (!in_cout[i]) s.push (i);}}} E_time[0] = 0; if (Sep < n-1) {n_s = 0; return;} int Juci = 0; for (i = 1; i < n; i++) {int t = Arry[i], for (j = 0; J < N; j + +) {if (Map[j][t]) {e_time[t] = max (e_t Ime[j]+map[j][t], e_time[t]);} Juci = Max (Juci, e_time[t]);//record the maximum value on the entire route}sum = Juci;}} int main () {int I, J, V, U, W; memset (map, 0, sizeof (map)), memset (in_cout, 0, sizeof (in_cout)), scanf ("%d%d", &n,& AMP;E); for(i = 0; i < e; i++) {scanf ("%d%d%d", &v,&u,&w), if (W) {map[v][u] = W; in_cout[u]++;}} Get_et (), if (n_s) printf ("%d\n", sum), elseprintf ("impossible\n"); return 0;}
Critical path Algorithm (PAT how Long Does It take (25))