Hdu 1596 find the safest road (product shortest)

Source: Internet
Author: User

Question:

Link: Click to open the link

Question:

Ideas:

Just make a slight modification to dijkstra. The product is changed every time dis [] is updated.

Code:

#include 
 
  #include 
  
   #include 
   
    using namespace std;#define INF 100000000const int N = 1010;int n,m;double map[N][N],dis[N];int st,ed;void dijkstra(){    int vis[N];    memset(vis,0,sizeof(vis));    for(int i=1; i<=n; i++)    {        dis[i] = map[st][i];    }    for(int i=1; i
    
      1e-6)            {                maxx = dis[x=y];            }        }        vis[x] = 1;        for(int y=1; y<=n; y++)        {            if(maxx*map[x][y] - dis[y] > 1e-6)                dis[y] = maxx*map[x][y];        }    }    if(dis[ed])        printf("%.3lf\n",dis[ed]);    else        printf("What a pity!\n");}int main(){    //freopen("input.txt","r",stdin);    double s;    while(scanf("%d",&n) != EOF)    {        for(int i=1; i<=n; i++)        {            for(int j=1; j<=n; j++)            {                scanf("%lf",&s);                map[i][j] = s;            }        }        scanf("%d",&m);        for(int i=1; i<=m; i++)        {            scanf("%d%d",&st,&ed);            dijkstra();        }    }    return 0;}
    
   
  
 
---------------------------------------------------------------

Gains:

---------------------------------------------------------------

Fighting, never shrinking; fighting, never stopping ~~~~~~~~~

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.