1869 Shortest Path, freloy's algorithm. cpp

Source: Internet
Author: User

# Include <stdio. h>

# Include <math. h>

# Include <stdlib. h>

# Define Max 2 <10 // This number cannot be too large or too small. When the two numbers are too large, they are out of range. The first value is 2 <29; the result is wa.

Int map [105] [105];

Int d [105] [105];

Int main (INT argc, char * argv [])

{

Int N, I, J, K, T, M;

Int A, B;

While (scanf ("% d", & N, & M )! = EOF ){

For (I = 0; I <105; I ++) // initialization ..

For (j = 0; j <105; j ++)

Map [I] [J] = max;

For (I = 0; I <m; I ++ ){

Scanf ("% d", & A, & B );

If (A = B)

Map [a] [B] = map [B] [a] = 0;

Else map [a] [B] = map [B] [a] = 1;

}

For (I = 0; I <n; I ++) // initialization...

For (j = 0; j <n; j ++)

If (I = J) d [I] [J] = 0;

Else d [I] [J] = d [J] [I] = map [I] [J];

For (k = 0; k <n; k ++) // freeloj's algorithm .. Don't mess up the order...

For (I = 0; I <n; I ++)

For (j = 0; j <n; j ++)

If (d [I] [J]> d [I] [k] + d [k] [J])

D [I] [J] = d [I] [k] + d [k] [J];

Int flag = 0;

For (I = 0; I <n; I ++ ){

For (j = 0; j <n; j ++)

If (d [I] [J]> 7) {// The question is separated by a maximum of six people, corresponding to Seven sides...

Flag = 1;

Break;

}

}

If (flag = 1)

Printf ("NO \ n ");

Else printf ("Yes \ n ");

}

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.