码迷,mamicode.com
首页 > 其他好文 > 详细

1155. Can I Post the lette

时间:2015-01-13 23:24:40      阅读:396      评论:0      收藏:0      [点我收藏+]

标签:c++   c语言   算法   sicily   

#include "iostream"
#include "memory.h"
#include "cstdio"
using namespace std;

int road[201][201];
int n, m;
/*
利用弗洛伊德算法来解这道题,如果两个城市可以连通,
则其距离为0
*/
inline void floyd(){
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			for (int k = 0; k < n; k++){
				if (road[j][k] > (road[j][i] + road[i][k])){
					road[j][k] = road[j][i] + road[i][k];
				}
			}
		}
	}
}

int main(){
	while (cin >> n && n){
		if (0 == n)
			break;
		for (int i = 0; i < 201; i++){
			for (int j = 0; j < 201; j++){
			road[i][j] = 100;
			}
			road[i][i] = 0;
		}
		
		cin >> m;
		for (int i = 0; i < m; i++){
			int a, b;
			cin >> a >> b;
			road[a][b] = 0;
			road[b][a] = 0;
		}
		floyd();
		if (road[0][n - 1] == 0){
			printf("I can post the letter\n");
		}
		else{
			printf("I can't post the letter\n");
		}
	}

	return 0;
}

1155. Can I Post the lette

标签:c++   c语言   算法   sicily   

原文地址:http://blog.csdn.net/liujan511536/article/details/42684507

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!