//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. JS事件整理

    onclick 鼠标点击事件 ondblclick 鼠标双击事件 onmouseover 鼠标移入事件 onmouseout 鼠标移出事件 onmousedown 鼠标按下事件 onmousemove ...

  2. oracle分区提高篇

      一. 分区表理论知识 Oracle提供了分区技术以支持VLDB(Very Large DataBase).分区表通过对分区列的判断,把分区列不同的记录,放到不同的分区中.分区完全对应用透明. Or ...

  3. Android:Butter Knife 8.0.1配置

    github地址:https://github.com/GarsonZhang/butterknife Butter Knife Field and method binding for Androi ...

  4. php进制转换函数

    1 十进制(decimal system)转换函数 ① 十进制转二进制 string  decbin(int number). 参数为一个十进制整型数字,不是整型数字会自动转为整型数字,如'3'转为3 ...

  5. [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:实现基本的CRUD功能

    英文渣水平,大伙凑合着看吧…… 这是微软官方SignalR 2.0教程Getting Started with Entity Framework 6 Code First using MVC 5 系列 ...

  6. [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:为ASP.NET MVC应用程序实现继承

    这是微软官方教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译,这里是第十一篇:为ASP.NET MVC应用程 ...

  7. 使用VB6制作RTD函数

    以前模仿大神在vs里使用c#实现RTD函数功能.(真是很生僻的东东啊)C#制作RTD参考:大神博客跳转.最近想VB里能不能做?就试着做了做,好像基本成了,整套代码有些毛病,勉强能算个样子,暂时不打算再 ...

  8. Android 签名工具 shell脚本

    signApk.sh #!/bin/bash #$1 signed and unaligned apk #$2 unsigned apk #$3 aligned apk #./signApk.sh t ...

  9. iOS - OC NSStream 文件流

    前言 @interface NSStream : NSObject @interface NSOutputStream : NSStream 1.文件流的使用 NSString *filePath = ...

  10. PLS-00221: 'function' 不是过程或尚未定义

    直接调用addOrgunitInfoByBatch(r_user_batch.seq_id,'01');   报错PLS-00221: 'function' 不是过程或尚未定义   原因是在调用函数时 ...