1. //Accepted 320 KB 16 ms
  2. //有n个顶点,边权用A表示
  3. //给出下三角矩阵,求从一号顶点出发到各点的最短路的最大值
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <iostream>
  7. #include <queue>
  8. #include <cmath>
  9. #include <algorithm>
  10. using namespace std;
  11. /**
  12. * This is a documentation comment block
  13. * 如果有一天你坚持不下去了,就想想你为什么走到这儿!
  14. * @authr songt
  15. */
  16. ;
  17. const int imax_e = imax_n*imax_n;
  18. ;
  19. struct node
  20. {
  21. int u,v,c;
  22. node(,,):u(u),v(v),c(c)
  23. {
  24.  
  25. }
  26. }p[imax_e];
  27. int head[imax_n];
  28. int next[imax_e];
  29. bool vis[imax_n];
  30. int dis[imax_n];
  31. int cnt[imax_n];
  32. int n;
  33. ;
  34. void init()
  35. {
  36. memset(head,-,sizeof(head));
  37. memset(next,-,sizeof(next));
  38. e=;
  39. }
  40. void addEdge(int u,int v,int c)
  41. {
  42. p[e]=node(u,v,c);
  43. next[e]=head[u];
  44. head[u]=e++;
  45. }
  46. bool relax(int u,int v,int c)
  47. {
  48. if (dis[v]>dis[u]+c)
  49. {
  50. dis[v]=dis[u]+c;
  51. return true;
  52. }
  53. return false;
  54. }
  55. queue<int > q;
  56. bool spfa(int src)
  57. {
  58. while (!q.empty()) q.pop();
  59. memset(vis,,sizeof(vis));
  60. memset(cnt,,sizeof(cnt));
  61. ;i<=n;i++)
  62. dis[i]=inf;
  63. dis[src]=;
  64. q.push(src);
  65. vis[src]=;
  66. cnt[src]++;
  67. while (!q.empty())
  68. {
  69. int pre=q.front();
  70. q.pop();
  71. vis[pre]=;
  72. ;i=next[i])
  73. {
  74. if (relax(pre,p[i].v,p[i].c) && !vis[p[i].v])
  75. {
  76. if ((++cnt[p[i].v])>=n) return false;
  77. vis[p[i].v]=;
  78. q.push(p[i].v);
  79. }
  80. }
  81. }
  82. return true;
  83. }
  84. ];
  85. int main()
  86. {
  87. while (scanf("%d",&n)!=EOF)
  88. {
  89. init();
  90. ;i<=n;i++)
  91. {
  92. ;j<i;j++)
  93. {
  94. scanf("%s",s);
  95. ]=='x') continue;
  96. int c=atoi(s);
  97. //printf("c=%d\n",c);
  98. addEdge(i,j,c);
  99. addEdge(j,i,c);
  100. }
  101. }
  102. spfa();
  103. ;
  104. ;i<=n;i++)
  105. if (dis[i]>ans) ans=dis[i];
  106. printf("%d\n",ans);
  107. }
  108. ;
  109. }

poj1502 spfa最短路的更多相关文章

  1. NOIP2013 华容道 (棋盘建图+spfa最短路)

    #include <cstdio> #include <algorithm> #include <cstring> #include <queue> # ...

  2. hiho(1081),SPFA最短路,(非主流写法)

    题目链接:http://hihocoder.com/problemset/problem/1081 SPFA求最短路,是不应-羁绊大神教我的,附上头像. 我第一次写SPFA,我用的vector存邻接表 ...

  3. hdu 5545 The Battle of Guandu spfa最短路

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5545 题意:有N个村庄, M 个战场: $ 1 <=N,M <= 10^5 $; 其中曹 ...

  4. HNU 13375 Flowery Trails (spfa最短路)

    求最短路径覆盖的全部边权值和. 思路:分别从起点和终点两次求最短路,再比较两个点到起点的距离和他们之间的权值相加和是否等于最短路径. 这题很好 #include <cstring> #in ...

  5. poj 1847 Tram【spfa最短路】

    Tram Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12005   Accepted: 4365 Description ...

  6. BZOJ 1003 物流运输 (动态规划 SPFA 最短路)

    1003: [ZJOI2006]物流运输 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 5590 Solved: 2293 [Submit][Stat ...

  7. POJ - 1062(昂贵的聘礼)(有限制的spfa最短路)

    题意:...中文题... 昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 54350   Accepted: 16 ...

  8. POJ 1556 - The Doors - [平面几何+建图spfa最短路]

    题目链接:http://poj.org/problem?id=1556 Time Limit: 1000MS Memory Limit: 10000K Description You are to f ...

  9. ZOJ 2760 - How Many Shortest Path - [spfa最短路][最大流建图]

    人老了就比较懒,故意挑了到看起来很和蔼的题目做,然后套个spfa和dinic的模板WA了5发,人老了,可能不适合这种刺激的竞技运动了…… 题目链接:http://acm.zju.edu.cn/onli ...

随机推荐

  1. 解读HTML 5新语法 提高语义价值

    HTML 5的新标记 设计者们需要完成的任务是要给HTML 5开发一个更丰富的和更有含义的语义,当然可以想象这种新方案将会是很灵活和很高效的,同时与所有的现代互联网标准相适应.下面就是一些将要在HTM ...

  2. JavaScript高级应用(二)(转)

    1.组件是否安装 //组件是否安装 isComponentInstalled("{6B053A4B-A7EC-4D3D-4567-B8FF8A1A5739}", "com ...

  3. NSRuntime RunLoop

    Objective-C总Runtime的那点事儿(一)消息机制 http://www.cocoachina.com/ios/20141018/9960.html Runtime运行时的那点事儿 htt ...

  4. Unity3D之协程(Coroutines & Yield )

    在Unity中StartCoroutine/yield return这个模式到底是怎么应用的? 比如你要一个方法进行一个比较耗时的复杂运算~同时又想让脚本流畅的进行其他操作而不是卡在那里等该方法执行完 ...

  5. GZFramwork数据库层《前言》DLL项目引用

    新建项目: 1. 项目引入GZFramwork.dll NuGet地址:Install-Package GZFramwork 每个项目都引用 2.BLL层 设置数据库连接维护类:继承于:GZFramw ...

  6. Jenkins RCE2(CVE-2016-0788)EXP

    国内应该有这个EXP的不多,需要点JAVA基础,安装好maven之后,配置下就可以了,官网也给出了样例,乌云也给了分析.

  7. 小计-git

    今天在发布项目的时候遇到了一个问题,就是项目一直提示与最新版本有差异,导致发布不不成功.仔细考虑了一下,自己这次的开发与原来的是不一样的,父子工程,不是单模块开发,发现原来是别人发布过他们的模块到ma ...

  8. Deep Learning 9_深度学习UFLDL教程:linear decoder_exercise(斯坦福大学深度学习教程)

    前言 实验内容:Exercise:Learning color features with Sparse Autoencoders.即:利用线性解码器,从100000张8*8的RGB图像块中提取颜色特 ...

  9. Hibernate 中出现 XXXX is not mapped 问题

    1.查询的不是数据库名是实体名…Entity 2.也许是你where条件后的字段名称写错了

  10. git diff patch

    如何生成patch:修改一个地方,然后git diff > xxx.patch 就会生成一个patch文件,这里的关键似乎是, 源文件的某个模块的版本要和线上发布的最新版本要一致,这样patch ...