HDU 5137 Shortest Path maximization

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=5137

Rt

N is only 30, using SPFA to traverse each of the point methods to find the maximum value

<span style= "FONT-SIZE:14PX;" > #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include < string> #include <queue> #include <map> #include <iostream> #include <sstream> #include < algorithm>using namespace std; #define RD (x) scanf ("%d", &x) #define RD2 (x, y) scanf ("%d%d", &x,&y) #define RD3 (x, Y, z) scanf ("%d%d%d", &x,&y,&z) #define CLR0 (x) memset (x,0,sizeof (×)) #define CLR1 (x) memset (X,-1, sizeof (x)) #define EPS 1e-9const double pi = ACOs ( -1.0); typedef long long ll;const int inf = 1000000000;const int MAXN = 10 05;struct edge{int v,next,c;}    E[maxn<<1];int n,m,head[40],ecnt;bool vis[40];void Add (int u,int v,int c) {e[ecnt] = (edge) {v,head[u],c};    Head[u] = ecnt++;    E[ECNT] = (edge) {u,head[v],c}; HEAD[V] = ecnt++;}    int dis[40];void SPFA () {for (int i = 1;i <= n;++i) dis[i] = inf;    Dis[1] = 0;    Clr0 (VIS);    Queue<int> Q;    Q.push (1); vis[1] = 1; while (!q.emPty ()) {int u = q.front (); Q.pop ();        Vis[u] = false;            for (int i = head[u];i! = -1;i = e[i].next) {int v = E[I].V;                if (Dis[v] > Dis[u] + e[i].c) {Dis[v] = Dis[u] + e[i].c;                    if (!vis[v]) {vis[v] = 1;                Q.push (v);    }}}}}int u[maxn],v[maxn],c[maxn],mx = 0;int mp[40][40];void work () {CLR0 (MP);    mx = 0;        for (int i = 0;i < M;++i) {RD3 (u[i],v[i],c[i]);    Mp[u[i]][v[i]] = mp[u[i]][v[i]] = c[i];        } for (int i = 2;i < N;++i) {CLR1 (head);        ecnt = 0;            for (int j = 0;j < M;++j) {if (i = = U[j] | | i = v[j]) continue;        Add (U[j],v[j],c[j]);  }//for (int j = 1;j <= n;++j)//for (int k = 1;k <= n;++k) {//if (i = = J | | i = = k | |    !MP[J][K]//continue;//Add (J,k,mp[j][k]);/} SPFA ();    MX = max (mx,dis[n]);    } if (mx = = inf) puts ("INF"); else printf ("%d\n", MX);}    int main () {//int _,cas = 1;//RD (_),//while (_--) {//printf ("Case #%d:%i64d\n", cas++,work ());/}    while (RD2 (n,m), n|m) {work (); } return 0;} /**/</span>


HDU 5137 Shortest Path maximization

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.