Poj 1502 MPI maelstrom-Dijkstra-atoi

Source: Internet
Author: User
/* First obtain the shortest path from each point to 1 and then find the prototype of the maximum value from the Shortest Path: int atoi (const char * nptr). Function Description: The nptr parameter, if the first non-space character does not exist or is neither a number nor a plus or minus sign, 0 is returned. Otherwise, type conversion is started and non-numbers (including Terminator \ 0) are detected) the conversion is stopped. The return value is an integer. */# Include <stdio. h> # include <stdlib. h> # include <string. h> int map [110] [110], vis [110], DIST [110], n; char s [1000]; int Zhao () {int I, xia =-1; for (I = 1; I <= N; I ++) if (vis [I] = 0 & (Xia =-1 | Dist [I] <Dist [Xia]) Xia = I; return Xia ;} int Dijkstra () {int max = 0, I, j, Xia; memset (VIS, 0, sizeof (VIS); vis [1] = 1; for (I = 1; I <= N; I ++) Dist [I] = map [1] [I]; for (I = 2; I <= N; I ++) {Xia = Zhao (); vis [Xia] = 1; for (j = 1; j <= N; j ++) if (vis [J] = 0 & Dist [J]> Dist [Xia] + map [Xia] [J]) dist [J] = DIST [Xia] + map [Xia] [J];} for (I = 2; I <= N; I ++) if (Dist [I]> MAX) max = DIST [I]; return Max;} int main () {int I, j, k; scanf ("% d ", & N); getchar (); for (I = 2; I <= N; I ++) {gets (s); j = 1; k = 0; while (s [k]) {If (s [k] = 'X') {map [I] [J ++] = 999999999; k = K + 2; continue;} map [I] [J ++] = atoi (S + k ); while (s [k]> = '0' & S [k] <= '9') K ++; while (s [k] = '') k ++ ;}}for (I = 1; I <= N; I ++) {for (j = I; j <= N; j ++) if (I = J) map [I] [I] = 0; else map [I] [J] = map [J] [I];} printf ("% d \ n", Dijkstra (); Return 0 ;}

 

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.