【POJ】3268 Silver Cow Party
题目链接:http://poj.org/problem?id=3268
题意 :有N头奶牛,M条单向路。X奶牛开party,其他奶牛要去它那里。每头奶牛去完X那里还要返回。去回都是走的最短路。现在问这里面哪头奶牛走的路最长。
题解:对每个奶牛i与X做两次spfa。去回各一次。然后统计最长的。。板子稍微改一改//但是我还是T了好几发,因为初始化数组的时候maxn开大了。。QAQ。改小了就过了。
代码:
#include<iostream>
#include<stack>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn = ; vector< pair<int,int> > e[maxn]; int n,m,X;
int d[maxn],inq[maxn]; int spfa(int s,int t){
for(int i = ;i < maxn ; i++)
inq[i] = ;
for(int i = ; i < maxn ; i++)
d[i] = 1e9;
queue<int>Q;
Q.push(s);d[s] = ;inq[s] = ;
while( !Q.empty() ){
int now = Q.front();
Q.pop();
inq[now] = ;
for(int i = ; i < e[now].size() ; i++){
int v = e[now][i].first;
if(d[v] > d[now] + e[now][i].second){
d[v] = d[now] + e[now][i].second;
if(inq[v] == )
continue;
inq[v] = ;
Q.push(v);
}
}
}
return d[t];
} int main() {
scanf("%d%d%d",&n,&m,&X);
int x,y,z;
for(int i = ; i < m ;i++){
scanf("%d%d%d",&x,&y,&z);
//cin>>x>>y>>z;
e[x].push_back(make_pair(y,z));
//e[y].push_back(make_pair(x,z));
} int ans = ;
for(int i = ;i <= n ;i++){
if(i == X){
continue;
}
int sum = spfa(X,i);
sum += spfa(i,X);
ans = max(ans,sum);
}
cout<<ans<<endl; return ;
}
【POJ】3268 Silver Cow Party的更多相关文章
- (poj)3268 Silver Cow Party 最短路
Description One cow ≤ N ≤ ) conveniently numbered ..N ≤ X ≤ N). A total of M ( ≤ M ≤ ,) unidirection ...
- Dijkstra算法:POJ No 3268 Silver Cow Party
题目:http://poj.org/problem?id=3268 题解:使用 priority_queue队列对dijkstra算法进行优化 #include <iostream> #i ...
- POJ 3268 Silver Cow Party (双向dijkstra)
题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
- 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算法的优化。
POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...
- POJ 3268 Silver Cow Party 最短路
原题链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
- 【POJ】1704 Georgia and Bob(Staircase Nim)
Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...
- 【POJ】1067 取石子游戏(博弈论)
Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...
- 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树
[BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...
随机推荐
- thinkphp 使用redis 整理(二) mark 一下
参考手册 http://www.cnblogs.com/weafer/archive/2011/09/21/2184059.html redis 几种数据类型选择,参考 : https://b ...
- 二叉树总结及部分Lintcode题目分析 1
1. 遍历问题 Preorder / Inorder / Postorder preorder: root left right inorder: left root right postorder: ...
- IDM自定义报错页面
由于用户两次重复单点登录会跳转至原生态ORACLE的错误页面页面.请提供配置方法.原因:是由于重复登录导致的.解决方案:Oracle官方给出了具体的解决方案,具体如下:I.创建战争档案a.创建目录&q ...
- redis 配置文件aof配置
redis 配置文件aof配置: bind 127.0.0.1 port 6379 daemonize yes dbfilename dump.rdb dir /new_renpeng/redis/ ...
- PHPExcel导出工作蒲(多表合并)教程+详细代码解读
最近做了一个需求,导出统计数据,因为需要同时导出多个不同的统计数据,所以不能像以往导出数据列表一样去实现这个需求,刚好空下来就记录一下(PHPExcel导出Excel多sheet合并) 一.主要使用的 ...
- ajax实现异步刷新
1. 导入 json 包: jackson-annotations-2.8.9.jar jackson-core-2.8.9.jar jackson-databind-2.8.9.jar json.j ...
- the blank final field factors may not have been initialized
Q1: why we should initialize final field before completion of new instance? final means no changeabl ...
- 3306端口被占用导致MySQL无法启动
报错:mysql服务无法启动1067 发现WINDOWS下面没有MYSQL的服务在MYSQL的安装目录bin下面安装MYSQL服务:C:\Program Files\MySQL\MySQL Serve ...
- utmp, wtmp - 登 录 记 录(login records)
SYNOPSIS[总览] #include DESCRIPTION[描述] utmp 文 件 用 于 记 录 当 前 系 统 用 户 是 哪 些 人. 但 是 实 际 的 人 数 可 能 比 这 个 ...
- php7 安装时需求的依赖包
php70 php70-bcmath php70-cli php70-common php70-devel php70-fpm php70-gd php70-json php70-mbstring p ...