//Accepted    320 KB    16 ms
 //有n个顶点,边权用A表示
 //给出下三角矩阵,求从一号顶点出发到各点的最短路的最大值
 #include <cstdio>
 #include <cstring>
 #include <iostream>
 #include <queue>
 #include <cmath>
 #include <algorithm>
 using namespace std;
 /**
   * This is a documentation comment block
   * 如果有一天你坚持不下去了,就想想你为什么走到这儿!
   * @authr songt
   */
 ;
 const int imax_e = imax_n*imax_n;
 ;
 struct node
 {
     int u,v,c;
     node(,,):u(u),v(v),c(c)
     {

     }
 }p[imax_e];
 int head[imax_n];
 int next[imax_e];
 bool vis[imax_n];
 int dis[imax_n];
 int cnt[imax_n];
 int n;
 ;
 void init()
 {
     memset(head,-,sizeof(head));
     memset(next,-,sizeof(next));
     e=;
 }
 void addEdge(int u,int v,int c)
 {
     p[e]=node(u,v,c);
     next[e]=head[u];
     head[u]=e++;
 }
 bool relax(int u,int v,int c)
 {
     if (dis[v]>dis[u]+c)
     {
         dis[v]=dis[u]+c;
         return true;
     }
     return false;
 }
 queue<int > q;
 bool spfa(int src)
 {
     while (!q.empty()) q.pop();
     memset(vis,,sizeof(vis));
     memset(cnt,,sizeof(cnt));
     ;i<=n;i++)
     dis[i]=inf;
     dis[src]=;
     q.push(src);
     vis[src]=;
     cnt[src]++;
     while (!q.empty())
     {
         int pre=q.front();
         q.pop();
         vis[pre]=;
         ;i=next[i])
         {
             if (relax(pre,p[i].v,p[i].c) && !vis[p[i].v])
             {
                 if ((++cnt[p[i].v])>=n) return false;
                 vis[p[i].v]=;
                 q.push(p[i].v);
             }
         }
     }
     return true;
 }
 ];
 int main()
 {
     while (scanf("%d",&n)!=EOF)
     {
         init();
         ;i<=n;i++)
         {
             ;j<i;j++)
             {
                 scanf("%s",s);
                 ]=='x') continue;
                 int c=atoi(s);
                 //printf("c=%d\n",c);
                 addEdge(i,j,c);
                 addEdge(j,i,c);
             }
         }
         spfa();
         ;
         ;i<=n;i++)
         if (dis[i]>ans) ans=dis[i];
         printf("%d\n",ans);
     }
     ;
 }

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. 31、springmvc(注解)

    回顾什么是springmvc,它与spring有什么关系 springmvc属于spring框架的后续产品,用在基于MVC的表现层开发,类似于struts2框架 参见<<springmvc ...

  2. WampServer中MySQL中文乱码解决

    1.修改mysql的my.ini文件: 在 [client] 下面增加 default-character-set=utf8 在 [mysqld] 下面增加: character_set_server ...

  3. HDU 5690:2016"百度之星" - 初赛 All X

    原文链接:https://www.dreamwings.cn/hdu5690/2657.html All X Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  4. Flowplayer-playlist

    SOURCE URL: https://flowplayer.org/docs/playlist.html HTML layout Here is a typical setup for a play ...

  5. C 语言中用bsearch()实现查找操作

    C语言中可以用bsearch()实现二分查找.同qsort()一样,bsearch()也包含在库中,且同样要自定义比较子函数.其原型如下: void *bsearch(const void *key, ...

  6. SQL Server 查询表的记录数(3种方法,推荐第一种)

    http://blog.csdn.net/smahorse/article/details/8156483 --SQL Server 查询表的记录数 --one: 使用系统表. SELECT obje ...

  7. Java精确计算小数

    Java在计算浮点数的时候,由于二进制无法精确表示0.1的值(就好比十进制无法精确表示1/3一样),所以一般会对小数格式化处理. 但是如果涉及到金钱的项目,一点点误差都不能有,必须使用精确运算的时候, ...

  8. js继承之call,apply和prototype随谈

    在js中,call,apply和prototype都可以实现对象的继承,下面我们看一个例子: function FatherObj1() { this.sayhello = "I am jo ...

  9. union (共用声明和共用一变量定义)

    "联合"是一种特殊的类,也是一种构造类型的数据结构.在一个"联合"内可以定义多种不同的数据类型, 一个被说明为该"联合"类型的变量中,允许装 ...

  10. STM32学习笔记(十) CAN通讯测试(环回模式)

    1.CAN通讯的理解 想学习CAN通讯,那么要对通讯协议有一定的认知.通讯协议是指通信双方对数据传送控制的一种约定.约定中包括对数据格式,同步方式,传输速度,传送步骤,检纠错方式以及控制字符定义等问题 ...