Critical path Algorithm (PAT how Long Does It take (25))

Source: Internet
Author: User
Tags in degrees

#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))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.