1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define INF 0x3f3f3f3f
  4. int dis[];
  5. int visit[];
  6. int SSSP[][];
  7. void dijkstra(int x,int n)
  8. {
  9. int pos;
  10. int minn;
  11. for(int i=;i<=n;i++)
  12. {
  13. dis[i]=SSSP[][i];
  14. }
  15. visit[x]=;
  16. dis[x]=;
  17. for(int i=;i<=n;i++)
  18. {
  19. minn=INF;
  20. pos=;
  21. for(int j=;j<=n;j++)
  22. {
  23. if(!visit[j]&&dis[j]<minn)
  24. {
  25. pos=j;
  26. minn=dis[j];
  27. }
  28.  
  29. }
  30. if(pos==) break;
  31. else
  32. {
  33. visit[pos]=;
  34. for(int j=;j<=n;j++)
  35. {
  36. if(!visit[j]&& dis[pos]+SSSP[pos][j]<dis[j])
  37. dis[j]=dis[pos]+SSSP[pos][j];
  38. }
  39. }
  40.  
  41. }
  42. }
  43. int main()
  44. {
  45. while()
  46. {
  47. int n,m; cin>>n>>m;
  48. if(n==&&m==) break; int zzzzz=;
  49.  
  50. memset(visit,,sizeof(visit));
  51. memset(dis,,sizeof(dis));
  52. memset(SSSP,,sizeof(SSSP));
  53.  
  54. for(int i=;i<=n;i++)
  55. {
  56. for(int j=;j<=n;j++)
  57. SSSP[i][j]=INF;
  58. }
  59. int a[];
  60. int b[];
  61. int t[];
  62. for(int i=;i<=m;i++)
  63. {
  64. cin>>a[i]>>b[i]>>t[i];
  65. SSSP[a[i]][b[i]]=t[i];
  66. SSSP[b[i]][a[i]]=t[i];
  67. }
  68. dijkstra(,n); //cout<<"*****"<<dis[n]<<"*******"<<zzzzz<<"******"<<endl;
  69. if(dis[n]==INF)
  70. {
  71. zzzzz=;
  72. }
  73. int maxn=dis[n];
  74.  
  75. for(int i=;i<n;i++)
  76. {
  77. // qu dian chong ding yi
  78. if(zzzzz==) break;
  79. for(int j=;j<=n;j++)
  80. {
  81. for(int j1=;j1<=n;j1++)
  82. SSSP[j][j1]=INF;
  83. }
  84. for(int j=;j<=m;j++)
  85. {
  86. SSSP[a[j]][b[j]]=t[j];
  87. SSSP[b[j]][a[j]]=t[j];
  88. if(a[j]==i||b[j]==i)
  89. {
  90. SSSP[a[j]][b[j]]=INF;
  91. SSSP[b[j]][a[j]]=INF;
  92. }
  93. }
  94. // chong ding yi visit[] dis
  95.  
  96. memset(visit,,sizeof(visit));
  97. memset(dis,,sizeof(dis));
  98.  
  99. dijkstra(,n); // cout<<"*****"<<dis[n]<<"*******"<<zzzzz<<"******"<<endl;
  100. if(dis[n]==INF)
  101. {
  102. zzzzz=;
  103. }
  104. if(dis[n]>maxn) maxn=dis[n];
  105. }
  106. if(zzzzz==)
  107. cout<<maxn<<endl;
  108. if(zzzzz==)
  109. cout<<"Inf"<<endl;
  110. }
  111. }

hdu5173 How Many Maos Does the Guanxi Worth的更多相关文章

  1. hdu 5137 How Many Maos Does the Guanxi Worth 最短路 spfa

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  2. HDU 5137 How Many Maos Does the Guanxi Worth

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5120 ...

  3. hdoj 5137 How Many Maos Does the Guanxi Worth【最短路枚举+删边】

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  4. HDU5137 How Many Maos Does the Guanxi Worth(枚举+dijkstra)

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  5. How Many Maos Does the Guanxi Worth

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  6. HDU 5137 How Many Maos Does the Guanxi Worth 最短路 dijkstra

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  7. (hdoj 5137 floyd)How Many Maos Does the Guanxi Worth

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  8. 杭电5137How Many Maos Does the Guanxi Worth

    How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/5 ...

  9. ACM学习历程——HDU5137 How Many Maos Does the Guanxi Worth(14广州10题)(单源最短路)

    Problem Description    "Guanxi" is a very important word in Chinese. It kind of means &quo ...

随机推荐

  1. laravel文件上传(本人使用的ftp驱动配置,本地测试总结)

    1.电脑端在:控制面板->程序和功能->打开和关闭Window功能,安装:Internet信息服务的(Ftp服务器,web管理工具的IIS管理服务,万网服务的常见http功能) 2.在电脑 ...

  2. Win10系列:JavaScript 动画1

    在应用程序中使用动画会使应用显得更加生动,进而给用户带来良好的视觉效果.例如,当用户将某个项添加到列表时,新项不会立即出现在列表中,而是采用动画形式到达相应位置,并且列表中的其他项也采用动画形式移动到 ...

  3. 微信公众号 access_token 没有过期 却失效

    最近在开发微信项目的时候 access_token   缓存到 redis里面的,明明在两个小时的有效期内  微信却提示 "errcode":40001,"errmsg& ...

  4. learning ddr tRP and tRP tRTP CL tRAS

    referce :https://blog.csdn.net/ghostyu/article/details/7728106 tRP(RAS Precharge Time): “内存行地址控制器预充电 ...

  5. 计算机基础part1

    一:计算机的基本组成 1.计算机由输入单元.控制单元.算法逻辑单元.输出单元.存储单元,五大单元组成 二:概念篇 CPU:中央处理器,其内含有指令集(取码-解码-执行的过程) CPU同一时刻只能干一件 ...

  6. day28 黏包及黏包解决方案

    今日主要内容: 一 .缓冲区 二.两种黏包现象 三.黏包现象的两种解决方案 四.打印进度条(补充的,了解即可) 1. 缓冲区 缓冲区的作用 : 将程序和网络解耦(这样做的好处是程序不会以为网速的快慢而 ...

  7. 浅谈caffe中train_val.prototxt和deploy.prototxt文件的区别

    本文以CaffeNet为例: 1. train_val.prototxt  首先,train_val.prototxt文件是网络配置文件.该文件是在训练的时候用的. 2.deploy.prototxt ...

  8. VSTO:使用C#开发Excel、Word【3】

    <Visual Studio Tools for Office: Using C# with Excel, Word, Outlook, and InfoPath >——By Eric C ...

  9. rnn-手写数字识别-网络结构-shape

    手写数字识别经典案例,目标是: 1. 掌握tf编写RNN的方法 2. 剖析RNN网络结构 tensorflow编程 #coding:utf-8 import tensorflow as tf from ...

  10. Java总结篇系列:Java泛型(转)

    一. 泛型概念的提出(为什么需要泛型)? 首先,我们看下下面这段简短的代码: 1 public class GenericTest { 2 3 public static void main(Stri ...