hdu1596 Find the safest road

Source: Internet
Author: User

N times the table, or found the error, the original is the Floyd () written in the loop body ....

Shortcomings, a lot of advice.

14481443 2015-08-12 17:12:05 Accepted 1596 3588MS 15960K 1010 B C + +


#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
using namespace Std;

const int MAXN = 1005;
const int INF = 0XFFFFFF;

int n;
Double MAPS[MAXN][MAXN];
Double DIST[MAXN][MAXN];

void Floyd () {
for (int i = 1; I <= n; i++) {
for (Int J =1;j<=n; J + +) {
DIST[I][J] = Maps[i][j];
}
}
for (int k = 1; k <= N; k++) {
for (int i = 1; I <= n; i++) {
for (int j = 1; J <= N; j + +) {
if (Dist[i][j] < INF && Dist[k][j] <inf)
DIST[I][J] =max (Dist[i][j],dist[i][k] *dist[k][j]);
}
}
}
}

int main () {
int m, S, E;
while (scanf ("%d", &n)!=eof) {
memset (maps,0,sizeof (maps));
for (int i = 1; I <= n; i++) {
for (int j = 1; J <= N; j + +) {
scanf ("%lf", &maps[i][j]);
}
}
scanf ("%d", &m);
Floyd ();
while (m--) {
scanf ("%d%d", &s, &e);
if (dist[s][e] = = 0) {
printf ("What a pity!\n");
}else {
printf ("%.3lf\n", Dist[s][e]);
}
}
}
return 0;
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

hdu1596 Find the safest road

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.