1. #include <cstdlib>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <cassert>
  6. using namespace std;
  7. #define N 505
  8. int a[N];
  9. long long mat[N][N], cnt[N][N], han[N][N];
  10. int main() {
  11. int n, m, s, e;
  12. while (4 == scanf("%d%d%d%d", &n, &m, &s, &e)) {
  13. for (int i = ; i < n; ++i) {
  14. scanf("%d", a + i);
  15. }
  16. memset(mat, -, sizeof mat);
  17. memset(cnt, , sizeof cnt);
  18. memset(han, , sizeof han);
  19. while (m--) {
  20. int x, y, z;
  21. scanf("%d%d%d", &x, &y, &z);
  22. assert(!cnt[x][y]);
  23. mat[x][y] = mat[y][x] = z;
  24. cnt[x][y]++;
  25. cnt[y][x]++;
  26. han[x][y] = a[y];
  27. han[y][x] = a[x];
  28. }
  29. for (int i = ; i < n; ++i) {
  30. for (int j = ; j < n; ++j) {
  31. if (!cnt[j][i])continue;
  32. for (int k = ; k < n; ++k) {
  33. if (!cnt[i][k])continue;
  34. if (!cnt[j][k] || mat[j][k] > mat[j][i] + mat[i][k]) {
  35. mat[j][k] = mat[j][i] + mat[i][k];
  36. cnt[j][k] = cnt[j][i] * cnt[i][k];
  37. han[j][k] = han[j][i] + han[i][k];
  38. } else if (mat[j][k] == mat[j][i] + mat[i][k]) {
  39. cnt[j][k] += cnt[j][i] * cnt[i][k];
  40. han[j][k] = max(han[j][k], han[j][i] + han[i][k]);
  41. }
  42. }
  43. }
  44. }
  45. if (s == e) {
  46. cout << 1 << ' ' << a[s] << endl;
  47. } else {
  48. cout << cnt[s][e] << ' ' << a[s] + han[s][e] << endl;
  49. }
  50. }
  51. return 0;
  52. }
  53. /*
  54. 5 6 0 2
  55. 1 2 1 5 3
  56. 0 1 1
  57. 0 2 2
  58. 0 3 1
  59. 1 2 1
  60. 2 4 1
  61. 3 4 1
  62. */

Pat 1003 甲级的更多相关文章

  1. PAT(甲级)2017年秋季考试

    PAT(甲级)2017年秋季考试 D题红黑树待补21/30 大佬的代码,看着想哭,这才是艺术啊 A Cut Integer 模拟题 #include<bits/stdc++.h> usin ...

  2. PAT(甲级)2017年春季考试

    PAT(甲级)2017年春季考试 A.Raffle for Weibo Followers #include<bits/stdc++.h> using namespace std; int ...

  3. PAT 1003我要通过!

    PAT 1003 我要通过! 答案正确"是自动判题系统给出的最令人欢喜的回复.本题属于 PAT 的"答案正确"大派送 -- 只要读入的字符串满足下列条件,系统就输出&qu ...

  4. PAT 1003 我要通过!(20)(代码+思路)

    1003 我要通过!(20)(20 分)提问 "答案正确"是自动判题系统给出的最令人欢喜的回复.本题属于PAT的"答案正确"大派送 -- 只要读入的字符串满足下 ...

  5. 迪杰斯特拉算法——PAT 1003

    本文主要是将我对于我对于迪杰斯特拉算法的理解写出来,同时通过例题来希望能够加深对于算法的理解,其中有错误的地方希望大家指正. 迪杰斯特拉算法 我将这个算法理解成一个局部到整体的算法,这个方法确实越研究 ...

  6. PAT 1003. 我要通过!(20) JAVA

    参考http://blog.csdn.net/bin8632/article/details/50216297 答案正确"是自动判题系统给出的最令人欢喜的回复.本题属于PAT的"答 ...

  7. PAT 1003. 我要通过!(20)

    "答案正确"是自动判题系统给出的最令人欢喜的回复.本题属于PAT的"答案正确"大派送 -- 只要读入的字符串满足下列条件,系统就输出"答案正确&quo ...

  8. PAT 1003

    1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...

  9. PAT 1003. Emergency (25)

    1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

随机推荐

  1. CentOS7.6安装MYSQL8.0

    1.一般CentOS默认安装了mariadb,所以先查看是否安装mariadb,如果安装就需要先卸载mariadbrpm -qa|grep mariadbrpm -e mariadb-libs --n ...

  2. docker:轻量级图形页面管理工具Portainer

    1.介绍 docker 图形化管理提供了很多工具,有Portainer.Docker UI.Shipyard等等,本文主要介绍Portainer. Portainer是一个开源.轻量级Docker管理 ...

  3. 配置tomcat服务器内存大小中的Xms、Xmx、PermSize、MaxPermSize 详解

    1.参数的含义 -vmargs -Xms256m -Xmx512m -XX:PermSize=256M -XX:MaxPermSize=512M -vmargs 说明后面是VM的参数,所以后面的其实都 ...

  4. 第10课 面向对象的增强(default/delete、override/final)

    一.default和delete关键字 (一)编译器提供的“缺省函数” 1.类的成员函数:构造/析构函数.复制构造/复制赋值函数.移动构造/移动赋值函数. 2. 类的全局默认操作函数:operator ...

  5. android webview 全屏100%显示图片

    这里引用 第三方类库 implementation 'org.jsoup:jsoup:1.10.2' 定义工具类 HtmlUtils import org.jsoup.Jsoup; import or ...

  6. 快速排序详解(C语言/python)

    快速排序详解 介绍: 快速排序于C. A. R. Hoare在1960年提出,是针对冒泡排序的一种改进.它每一次将需要排序的部分划分为俩个独立的部分,其中一个部分的数比的数都小.然后再按照这个方法对这 ...

  7. docker 学习操作记录 4

    记录3 [BEGIN] // :: Connecting to ... Connection established. To escape to local shell, press Ctrl+Alt ...

  8. shell脚本监控httpd服务80端口状态

    监控httpd服务端口状态,根据端口判断服务器是否启动,如果没有启动则脚本自动拉起服务,如果服务正在运行则退出脚本程序:如果换成别的服务端口也可以,但是脚本程序需要做调整. #!/bin/bash # ...

  9. pyenv和pipenv简单使用

    一.安装pyenv 安装pyenv $ git clone git://github.com/yyuu/pyenv.git ~/.pyenv $ echo 'export PYENV_ROOT=&qu ...

  10. Python time strptime() 函数根据指定的格式把一个时间字符串解析为时间元组

    Python time strptime() 函数根据指定的格式把一个时间字符串解析为时间元组 import time dt=time.strptime('2019-08-08 11:32:23', ...