floyd90pts求调,玄关
  • 板块P2009 跑步
  • 楼主SwiftFlash
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/26 22:03
  • 上次更新2024/7/27 08:23:19
查看原帖
floyd90pts求调,玄关
791890
SwiftFlash楼主2024/7/26 22:03
#include <iostream>
using namespace std;

int n, k, f[105][105], tmp;
char c1, c2;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	for(int i = 1;i < n;i ++){
		cin >> tmp;
		f[i][i+1] = tmp;
		f[i+1][i] = tmp;
	}
	cin >> tmp;
	f[n][1] = tmp;
	f[1][n] = tmp;
	for(int i = 1;i <= k;i ++){
		cin >> c1 >> c2 >> tmp;
		f[c1-'A'+1][c2-'A'+1] = max(f[c1-'A'+1][c2-'A'+1], tmp);
		f[c2-'A'+1][c1-'A'+1] = max(f[c2-'A'+1][c1-'A'+1], tmp);
	}
	for(int i = 1;i <= 24;i ++){
		for(int j = 1;j <= 24;j ++){
			if(f[i][j] == 0)f[i][j] = 19198100;
			if(i == j)f[i][i] = 0;
		}
	}
	cin >> c1 >> c2;
	for(int k = 1;k <= n;k ++){
		for(int i = 1;i <= n;i ++){
			for(int j = 1;j <= n;j ++){
				f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
			}
		}
	}
	cout << f[c1-'A'+1][c2-'A'+1] << endl;
    return 0;
}
2024/7/26 22:03
加载中...