poj 3268(spfa)
http://poj.org/problem?id=3268
对于这道题,我想说的就是日了狗了,什么鬼,定义的一个数值的前后顺序不同,一个就TLE,一个就A,还16MS。
感觉人生观都奔溃了,果然,题目做多了总会见到鬼的!!!!!!
心累,不想写这个题了。
#include <stdio.h>
#include <string.h>
#include <queue>
#include <iostream>
#define inf 0x3f
#define Max1 1010
#define Max2 100010 using namespace std;
int m,n,x;
int mark[Max1];
int next[Max1];
int u[Max2]; //把13和14行交换一下,你得到了结果会完全不同。。
int v[Max2];
int w[Max2];
int a[Max2],b[Max2],c[Max2];
int dist[Max1];
int ans[Max1];
bool vis[Max1]; queue <int >s;
void init()
{
memset( vis,false,sizeof(vis));
while( !s.empty()) s.pop();
memset(dist,inf,sizeof( dist ));
dist[x]=;
for(int i=;i<=n;i++)
mark[i]=-;
} void spfa()
{
s.push( x );
vis[ x ] = true ;
while( !s.empty() )
{
int tmp = s.front();
s.pop();
vis[ tmp ] = false;
for(int i = mark[ tmp ] ; i != - ; i = next[ i ] )
{
if( dist[ tmp ] + w[ i ] < dist[ v[ i ] ])
{
dist[ v[ i ] ] = dist[ tmp ] + w[ i ];
if( !vis[ v[ i ] ] )
{
s.push( v[ i ] );
vis[ v[ i ] ] = true;
}
}
}
}
for( int i = ; i <= n ; i++ )
ans[ i ] += dist[ i ];
} int main()
{
// freopen("in.txt","r",stdin);
while(~scanf("%d%d%d",&n,&m,&x))
{
memset( ans , , sizeof( ans ) );
init();
for( int i = ; i <= m ; i++ )
{
scanf( "%d%d%d",&a[ i ],&b[ i ],&c[ i ] );
u[ i ] = a[ i ];
v[ i ] = b[ i ];
w[ i ] = c[ i ];
next[ i ] = mark [ u[ i ] ] ;
mark[ u[ i ] ] = i;
}
spfa();
init();
for( int i = ; i <= m ; i++ )
{
v[ i ] = a[ i ];
u[ i ] = b[ i ];
w[ i ] = c[ i ];
next[ i ] = mark[ u[ i ] ];
mark[ u[ i ] ] = i;
}
spfa();
int Max = ans[];
for( int i = ; i <= n ; i++ )
if( ans[ i ] > Max ) Max = ans[ i ];
printf("%d\n",Max);
}
return ;
}
poj 3268(spfa)的更多相关文章
- DIjkstra(反向边) POJ 3268 Silver Cow Party || POJ 1511 Invitation Cards
题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. PO ...
- POJ 3268 Silver Cow Party (最短路径)
POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...
- POJ 3268——Silver Cow Party——————【最短路、Dijkstra、反向建图】
Silver Cow Party Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...
- POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。
POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...
- 图论 ---- spfa + 链式向前星 ---- poj 3268 : Silver Cow Party
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12674 Accepted: 5651 ...
- POJ - 3268 Silver Cow Party SPFA+SLF优化 单源起点终点最短路
Silver Cow Party One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to ...
- POJ 3268 Dijkstra+priority_queue或SPFA
思路:正向建边,一遍Dijkstra,反向建边,再一遍Dijkstra.ans加在一起输出最大值. (SPFA也行--) // by SiriusRen #include <queue> ...
- Poj(2679),SPFA,邻接表(主流写法)
题目链接:http://poj.org/problem?id=3268 题意: 有编号为1-N的牛,它们之间存在一些单向的路径.给定一头牛的编号,其他牛要去拜访它并且拜访完之后要返回自己原来的位置,求 ...
- POJ 3268 Silver Cow Party 最短路
原题链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
随机推荐
- ssh-keygen不是内部或外部命令
在**/Git/usr/bin目录下找到ssh-keygen.exe,将**/Git/usr/bin路径添加到环境变量中
- mysql SELECT FOR UPDATE语句使用示例
以MySQL 的InnoDB 为例,预设的Tansaction isolation level 为REPEATABLE READ,在SELECT 的读取锁定主要分为两种方式:SELECT ... LO ...
- UCMA设置lync在线状态
摘要 UCMA全称Microsoft Unified Communications Managed API,主要用来构建工作在Microsoft Lync Server上的中间层应用程序.开发人员可以 ...
- js DOM Element属性和方法整理
节点操作,属性 1. childNodes.children 这两个属性获取到的子节点会根据浏览器的不同而不同的,所以一定要判断下nodeType是否为1. childNodes获取到的是NodeLi ...
- poj3335 半交平面,多边形内核
Rotating Scoreboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5300 Accepted: 21 ...
- js改变HTML元素的值
js改变HTML元素的值(常用,备忘) <!DOCTYPE html> <html> <body> <h1>我的第一段 JavaScript</h ...
- ThinkPHP报错处理
1,当运行结果提示:找不到该页面(控制器),怎么办? 建造一个空页面:EmptyController <?php namespace Home\Controller; use Think\Con ...
- 修改dedecms默认文章来源 "未知"改为关键词
在dedecms后台发表文章时文章来源是可选的,有时我们没有选择或没填写,那么前台默认文章来源即“未知”.如何将dedecms默认文章来源改为自己想要的关键词呢?即将“未知”改为“keyword”呢? ...
- Ubuntu 开机进入命令行模式
1.修改配置 sudo vim /etc/default/grub 把 GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" 改为 GRUB_CMDL ...
- “RESTful架构”相关资料收藏
[阮一峰]理解RESTful架构 [InfoQ]深入浅出REST 用于构建 RESTful Web 服务的多层架构 REST会是SOA的未来吗? Restful 与 SOA 的关系? 回答1: 注意r ...