首页 > 其他 > 详细

1155. Can I Post the lette

时间:2015-01-13 23:23:24      阅读:578      评论:0      收藏:0      [点我收藏+]
#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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!