poj1502 spfa最短路
- //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最短路的更多相关文章
- NOIP2013 华容道 (棋盘建图+spfa最短路)
#include <cstdio> #include <algorithm> #include <cstring> #include <queue> # ...
- hiho(1081),SPFA最短路,(非主流写法)
题目链接:http://hihocoder.com/problemset/problem/1081 SPFA求最短路,是不应-羁绊大神教我的,附上头像. 我第一次写SPFA,我用的vector存邻接表 ...
- hdu 5545 The Battle of Guandu spfa最短路
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5545 题意:有N个村庄, M 个战场: $ 1 <=N,M <= 10^5 $; 其中曹 ...
- HNU 13375 Flowery Trails (spfa最短路)
求最短路径覆盖的全部边权值和. 思路:分别从起点和终点两次求最短路,再比较两个点到起点的距离和他们之间的权值相加和是否等于最短路径. 这题很好 #include <cstring> #in ...
- poj 1847 Tram【spfa最短路】
Tram Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12005 Accepted: 4365 Description ...
- BZOJ 1003 物流运输 (动态规划 SPFA 最短路)
1003: [ZJOI2006]物流运输 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 5590 Solved: 2293 [Submit][Stat ...
- POJ - 1062(昂贵的聘礼)(有限制的spfa最短路)
题意:...中文题... 昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 54350 Accepted: 16 ...
- POJ 1556 - The Doors - [平面几何+建图spfa最短路]
题目链接:http://poj.org/problem?id=1556 Time Limit: 1000MS Memory Limit: 10000K Description You are to f ...
- ZOJ 2760 - How Many Shortest Path - [spfa最短路][最大流建图]
人老了就比较懒,故意挑了到看起来很和蔼的题目做,然后套个spfa和dinic的模板WA了5发,人老了,可能不适合这种刺激的竞技运动了…… 题目链接:http://acm.zju.edu.cn/onli ...
随机推荐
- 解读HTML 5新语法 提高语义价值
HTML 5的新标记 设计者们需要完成的任务是要给HTML 5开发一个更丰富的和更有含义的语义,当然可以想象这种新方案将会是很灵活和很高效的,同时与所有的现代互联网标准相适应.下面就是一些将要在HTM ...
- JavaScript高级应用(二)(转)
1.组件是否安装 //组件是否安装 isComponentInstalled("{6B053A4B-A7EC-4D3D-4567-B8FF8A1A5739}", "com ...
- NSRuntime RunLoop
Objective-C总Runtime的那点事儿(一)消息机制 http://www.cocoachina.com/ios/20141018/9960.html Runtime运行时的那点事儿 htt ...
- Unity3D之协程(Coroutines & Yield )
在Unity中StartCoroutine/yield return这个模式到底是怎么应用的? 比如你要一个方法进行一个比较耗时的复杂运算~同时又想让脚本流畅的进行其他操作而不是卡在那里等该方法执行完 ...
- GZFramwork数据库层《前言》DLL项目引用
新建项目: 1. 项目引入GZFramwork.dll NuGet地址:Install-Package GZFramwork 每个项目都引用 2.BLL层 设置数据库连接维护类:继承于:GZFramw ...
- Jenkins RCE2(CVE-2016-0788)EXP
国内应该有这个EXP的不多,需要点JAVA基础,安装好maven之后,配置下就可以了,官网也给出了样例,乌云也给了分析.
- 小计-git
今天在发布项目的时候遇到了一个问题,就是项目一直提示与最新版本有差异,导致发布不不成功.仔细考虑了一下,自己这次的开发与原来的是不一样的,父子工程,不是单模块开发,发现原来是别人发布过他们的模块到ma ...
- Deep Learning 9_深度学习UFLDL教程:linear decoder_exercise(斯坦福大学深度学习教程)
前言 实验内容:Exercise:Learning color features with Sparse Autoencoders.即:利用线性解码器,从100000张8*8的RGB图像块中提取颜色特 ...
- Hibernate 中出现 XXXX is not mapped 问题
1.查询的不是数据库名是实体名…Entity 2.也许是你where条件后的字段名称写错了
- git diff patch
如何生成patch:修改一个地方,然后git diff > xxx.patch 就会生成一个patch文件,这里的关键似乎是, 源文件的某个模块的版本要和线上发布的最新版本要一致,这样patch ...