//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. HTML5 属性 认知

    HTML5中 不支持  Html4.01的属性: <acronym> <applet> <basefont> <big> <center> ...

  2. 基于Opencv和Mfc的图像处理增强库GOCVHelper(索引)

    GOCVHelper(GreenOpen Computer Version Helper )是我在这几年编写图像处理程序的过程中积累下来的函数库.主要是对Opencv的适当扩展和在实现Mfc程序时候的 ...

  3. 使用IOS7原生API进行二维码条形码的扫描

    使用IOS7原生API进行二维码条形码的扫描 IOS7之前,开发者进行扫码编程时,一般会借助第三方库.常用的是ZBarSDK,IOS7之后,系统的AVMetadataObject类中,为我们提供了解析 ...

  4. filebeat 多行日志的处理

    配置文件位于/etc/filebeat/filebeat.yml,就是filebeat的主配置文件 打开文件,搜索multiline:,默认是注释的,常用的有如下三个配置: multiline: pa ...

  5. sql server数据库语句

    -- 3-5  创建表Studnetcreate table Student(Sno char(9) primary key,Sname char(20) UNIQUE,Ssex CHAR(2),Sa ...

  6. linux dynamic debug 官方教程

    下载内核后,文档在:Documentation/dynamic-debug-howto.txt 中文版本:http://www.oschina.net/translate/dynamic-debug- ...

  7. Count Primes - LeetCode

    examination questions Description: Count the number of prime numbers less than a non-negative number ...

  8. XAF应用开发教程-内置Attribute功能列表

    在 XAF 框架,一些用来生成一个业务应用程序的信息是在Attribute中指定.您可以将属性应用到业务类 (或它的成员) 指定验证规则,指定如何对数据进行显示. 设置关系类等.本主题提供了有关在何处 ...

  9. 配置org.springframework.scheduling.quartz.CronTriggerBean (转载)

    在项目中又用到了定时器,对于定时器的应用总是模模糊糊的,今天结合网上找到的资料与自己在项目中写的简单地在此写一下,以备需要时查阅. 一个Quartz的CronTrigger表达式分为七项子表达式,其中 ...

  10. 关于JS的数据类型的一些见解

    关于js里的数据类型这块,说下个人对它的一些见地 js中的数据类型可以归类两类, 简单数据类型:string,number,boolean,null,undefined 复杂数据类型:object 其 ...