【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 ...
随机推荐
- 破解极验(geetest)验证码
破解极验(geetest)验证码 这是两年前的帖子: http://www.v2ex.com/t/138479 一个月前的破解程序,我没用过 asp.net ,不知道是不是真的破解了, demo ...
- ORM-Dapper:Dapper列表
ylbtech-ORM-Dapper:Dapper列表 1.返回顶部 1.1. https://dapper-tutorial.net/ 1.2. 2.1. https://www.nuget.org ...
- PAT_A1092#To Buy or Not to Buy
Source: PAT A1092 To Buy or Not to Buy (20 分) Description: Eva would like to make a string of beads ...
- CTF杂项思路工具分享————2019/5/30
分享碰到的一些奇奇怪怪的杂项解题方式: 键盘坐标密码: 题目给出一段字符串:11 21 31 18 27 33 34 对照上面的表格,就可以很清晰的看出来密文为:QAZIJCV 猪圈码: 题目为: 一 ...
- ajaxFileUpload.js插件支持多文件上传的方法
前提条件:ajaxFileUpload.js插件多文件上传步骤:1.修改源码,(源码只支持单个文件的上传):复制代码 代码如下: //修改前代码------- //var oldElement = j ...
- 人人开源打包jar
先在renren-security执行mvn clean install 再到renren-admin目录下,执行mvn clean package,就可以打成renren-admin.jar 如果想 ...
- Centos光盘ISO安装过程再理解
ISO启动时的基本流程 vmlinuz -> 加载initrd.img -> 加载内核基本驱动 -> 挂载光盘至/run/install/repo -> 启动anaconda ...
- EM相关两个算法 k-mean算法和混合高斯模型
转自http://www.cnblogs.com/jerrylead/archive/2011/04/06/2006924.html http://www.cnblogs.com/jerrylead/ ...
- UncategorizedSQLException异常处理办法
如题,先贴console org.springframework.jdbc.UncategorizedSQLException: StatementCallback; uncategorized SQ ...
- 解决mac下,javac命令出现的乱码问题
今天突然检查我的jdk安装,发现出现了乱码 一,出现乱码