HDU 1869 FLOYD: Calculate the shortest distance between two points

Source: Internet
Author: User

Returns the shortest distance between two points.

// Memset (MAP, 0x1ffffff, sizeof (MAP); // The initialization method is incorrect.

The correct method for using memset is that the initial value is an 8-digit value. For example, memset (MAP, 0x3f, sizeof (MAP); If map is of the int type, it is initialized to four 3f, namely 0x3f3f3f3f.

# Include <iostream> using namespace STD; # define n 105int n, m; int map [N] [N]; void Floyd () {for (INT I = 0; I <n; I ++) for (Int J = 0; j <n; j ++) for (int K = 0; k <n; k ++) {If (Map [J] [I] + map [I] [k] <map [J] [k]) map [J] [k] = map [J] [I] + map [I] [k] ;}} int main () {While (~ Scanf ("% d", & N, & M) {// memset (MAP, 0x1ffffff, sizeof (MAP )); // incorrect Initialization Method for (INT I = 0; I <n; I ++) for (Int J = 0; j <n; j ++) map [I] [J] = 0x1fffff; int X, Y; For (INT I = 0; I <m; I ++) {scanf ("% d ", & X, & Y); map [x] [Y] = map [y] [x] = 1 ;}for (INT I = 0; I <N; I ++) map [I] [I] = 0; Floyd (); int flag = 0; For (INT I = 0; I <n & flag = 0; I ++) {for (Int J = 0; j <n; j ++) {If (Map [I] [J]> 7) {flag = 1; break ;}}if (flag = 1) cout <"no" <Endl; else cout <"yes" <Endl;} 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.