Pat 1003 甲级
#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
*/
Pat 1003 甲级的更多相关文章
- PAT(甲级)2017年秋季考试
PAT(甲级)2017年秋季考试 D题红黑树待补21/30 大佬的代码,看着想哭,这才是艺术啊 A Cut Integer 模拟题 #include<bits/stdc++.h> usin ...
- PAT(甲级)2017年春季考试
PAT(甲级)2017年春季考试 A.Raffle for Weibo Followers #include<bits/stdc++.h> using namespace std; int ...
- PAT 1003我要通过!
PAT 1003 我要通过! 答案正确"是自动判题系统给出的最令人欢喜的回复.本题属于 PAT 的"答案正确"大派送 -- 只要读入的字符串满足下列条件,系统就输出&qu ...
- PAT 1003 我要通过!(20)(代码+思路)
1003 我要通过!(20)(20 分)提问 "答案正确"是自动判题系统给出的最令人欢喜的回复.本题属于PAT的"答案正确"大派送 -- 只要读入的字符串满足下 ...
- 迪杰斯特拉算法——PAT 1003
本文主要是将我对于我对于迪杰斯特拉算法的理解写出来,同时通过例题来希望能够加深对于算法的理解,其中有错误的地方希望大家指正. 迪杰斯特拉算法 我将这个算法理解成一个局部到整体的算法,这个方法确实越研究 ...
- PAT 1003. 我要通过!(20) JAVA
参考http://blog.csdn.net/bin8632/article/details/50216297 答案正确"是自动判题系统给出的最令人欢喜的回复.本题属于PAT的"答 ...
- PAT 1003. 我要通过!(20)
"答案正确"是自动判题系统给出的最令人欢喜的回复.本题属于PAT的"答案正确"大派送 -- 只要读入的字符串满足下列条件,系统就输出"答案正确&quo ...
- PAT 1003
1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...
- PAT 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
随机推荐
- CentOS7.6安装MYSQL8.0
1.一般CentOS默认安装了mariadb,所以先查看是否安装mariadb,如果安装就需要先卸载mariadbrpm -qa|grep mariadbrpm -e mariadb-libs --n ...
- docker:轻量级图形页面管理工具Portainer
1.介绍 docker 图形化管理提供了很多工具,有Portainer.Docker UI.Shipyard等等,本文主要介绍Portainer. Portainer是一个开源.轻量级Docker管理 ...
- 配置tomcat服务器内存大小中的Xms、Xmx、PermSize、MaxPermSize 详解
1.参数的含义 -vmargs -Xms256m -Xmx512m -XX:PermSize=256M -XX:MaxPermSize=512M -vmargs 说明后面是VM的参数,所以后面的其实都 ...
- 第10课 面向对象的增强(default/delete、override/final)
一.default和delete关键字 (一)编译器提供的“缺省函数” 1.类的成员函数:构造/析构函数.复制构造/复制赋值函数.移动构造/移动赋值函数. 2. 类的全局默认操作函数:operator ...
- android webview 全屏100%显示图片
这里引用 第三方类库 implementation 'org.jsoup:jsoup:1.10.2' 定义工具类 HtmlUtils import org.jsoup.Jsoup; import or ...
- 快速排序详解(C语言/python)
快速排序详解 介绍: 快速排序于C. A. R. Hoare在1960年提出,是针对冒泡排序的一种改进.它每一次将需要排序的部分划分为俩个独立的部分,其中一个部分的数比的数都小.然后再按照这个方法对这 ...
- docker 学习操作记录 4
记录3 [BEGIN] // :: Connecting to ... Connection established. To escape to local shell, press Ctrl+Alt ...
- shell脚本监控httpd服务80端口状态
监控httpd服务端口状态,根据端口判断服务器是否启动,如果没有启动则脚本自动拉起服务,如果服务正在运行则退出脚本程序:如果换成别的服务端口也可以,但是脚本程序需要做调整. #!/bin/bash # ...
- pyenv和pipenv简单使用
一.安装pyenv 安装pyenv $ git clone git://github.com/yyuu/pyenv.git ~/.pyenv $ echo 'export PYENV_ROOT=&qu ...
- Python time strptime() 函数根据指定的格式把一个时间字符串解析为时间元组
Python time strptime() 函数根据指定的格式把一个时间字符串解析为时间元组 import time dt=time.strptime('2019-08-08 11:32:23', ...