Pat 1003 甲级
2024-09-07 05:11:25
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cstdio>
#include <cassert>
using namespace std;
#define N 505
int a[N];
long long mat[N][N], cnt[N][N], han[N][N];
int main() {
int n, m, s, e;
while (4 == scanf("%d%d%d%d", &n, &m, &s, &e)) {
for (int i = ; i < n; ++i) {
scanf("%d", a + i);
}
memset(mat, -, sizeof mat);
memset(cnt, , sizeof cnt);
memset(han, , sizeof han);
while (m--) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
assert(!cnt[x][y]);
mat[x][y] = mat[y][x] = z;
cnt[x][y]++;
cnt[y][x]++;
han[x][y] = a[y];
han[y][x] = a[x];
}
for (int i = ; i < n; ++i) {
for (int j = ; j < n; ++j) {
if (!cnt[j][i])continue;
for (int k = ; k < n; ++k) {
if (!cnt[i][k])continue;
if (!cnt[j][k] || mat[j][k] > mat[j][i] + mat[i][k]) {
mat[j][k] = mat[j][i] + mat[i][k];
cnt[j][k] = cnt[j][i] * cnt[i][k];
han[j][k] = han[j][i] + han[i][k];
} else if (mat[j][k] == mat[j][i] + mat[i][k]) {
cnt[j][k] += cnt[j][i] * cnt[i][k];
han[j][k] = max(han[j][k], han[j][i] + han[i][k]);
}
}
}
}
if (s == e) {
cout << 1 << ' ' << a[s] << endl;
} else {
cout << cnt[s][e] << ' ' << a[s] + han[s][e] << endl;
}
}
return 0;
}
/*
5 6 0 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1
*/
最新文章
- pymol installation
- iOS开发--应用崩溃日志揭秘(二)
- Android之ListView的getItemViewType和getViewTypeCount
- Odoo Graph 指定默认 类型
- MVC3 新建项目
- oracle远程连接配置
- 一步一步搭建客服系统 (4) 客户列表 - JS($.ajax)调用WCF 遇到的各种坑
- 《REWORK》启示录 发出你的心声——程序员与身体
- Python-requests之POST Data的json问题
- HDU1312——Red and Black(DFS)
- Android 环境变量配置(Mac)
- 基于ATmgea8单片机设计的加热控制系统(转)
- JS 禁止刷新和右键
- Vim按Esc后光标左移问题的解决
- Python 项目实践一(外星人入侵小游戏)第二篇
- SqlSessionFactoryUtil
- Python学习:经典编程例题
- left join中where与on的区别
- is not in the sudoers file解决方法
- c#new和override