Silver Cow Party
Description
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤
X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road
i requires Ti (1 ≤ Ti ≤ 100) units of time to traverse.
Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way.
Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?
Input
N, M, and X
Lines 2.. M+1: Line i+1 describes road i with three space-separated integers:
Ai, Bi, and Ti. The described road runs from farm
Ai to farm Bi, requiring Ti time units to traverse.
Output
Sample Input
4 8 2
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3
Sample Output
10
Hint
题解:还是正向建图和逆向建图。就是求往返路程中最大的一条。
djistra:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue> using namespace std; const int INF= 0x3fffffff; int map[2][1003][1003];
bool visited[1003];
int d[1003];
int ans[1003]; int max(int a,int b)
{
return a > b ? a : b;
} void prim(int n,int s,int flag)
{
memset(visited,false,sizeof(visited));
for(int i = 1;i <= n;i++)
{
d[i] = map[flag][s][i];
//cout<<d[i]<<endl;
}
visited[s] = true;
for(int i = 1;i < n;i++)
{
int min = INF;
int k;
for(int j = 1;j <= n;j++)
{
if(!visited[j] && min > d[j])
{
min = d[j];
k = j;
}
}
if(min == INF)
{
break;
}
visited[k] = true;
for(int j = 1;j <= n;j++)
{
if(!visited[j] && d[j] > d[k] + map[flag][k][j])
{
d[j] = d[k] + map[flag][k][j];
}
}
}
} int main()
{
int n,m,st;
while(scanf("%d%d%d",&n,&m,&st) != EOF)
{
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= n;j++)
{
if(i == j)
{
map[0][i][j] = 0;
map[1][i][j] = 0;
}
else
{
map[0][i][j] = INF;
map[1][i][j] = INF;
}
}
} int u,v,c;
for(int i = 0;i < m;i++)
{
scanf("%d%d%d",&u,&v,&c);
map[0][u][v] = c;
map[1][v][u] = c;
} prim(n,st,1);
for(int i = 1;i <= n;i++)
{
ans[i] = d[i];
}
prim(n,st,0);
int res = 0;
for(int i = 1;i <= n;i++)
{
ans[i] += d[i];
res = max(res,ans[i]);
} printf("%d\n",res);
} return 0;
}
Silver Cow Party的更多相关文章
- 图论 ---- spfa + 链式向前星 ---- poj 3268 : Silver Cow Party
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12674 Accepted: 5651 ...
- Silver Cow Party(最短路,好题)
Silver Cow Party Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...
- 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 (Dijkstra)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13982 Accepted: 6307 ...
- poj 3268 Silver Cow Party
S ...
- POJ 3268 Silver Cow Party (最短路dijkstra)
Silver Cow Party 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/D Description One cow fr ...
- poj 3268 Silver Cow Party(最短路)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17017 Accepted: 7767 ...
- TOJ1693(Silver Cow Party)
Silver Cow Party Time Limit(Common/Java):2000MS/20000MS Memory Limit:65536KByte Total Submit: ...
- POJ3268 Silver Cow Party(dijkstra+矩阵转置)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15156 Accepted: 6843 ...
- POJ 3268 Silver Cow Party (Dijkstra)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions:28457 Accepted: 12928 ...
随机推荐
- TCP/IP具体解释--TCP/UDP优化设置总结& MTU的相关介绍
首先要看TCP/IP协议,涉及到四层:链路层,网络层.传输层,应用层. 当中以太网(Ethernet)的数据帧在链路层 IP包在网络层 TCP或UDP包在传输层 TCP或UDP中的数据(Data)在应 ...
- linux下使用free命令查看实际内存占用(可用内存)
转:http://blog.is36.com/linux_free_command_for_memory/ linux下在终端环境下可以使用free命令看到系统实际使用内存的情况,一般用free -m ...
- Unity技术面试题
一:什么是协同程序?答:在主线程运行时同时开启另一段逻辑处理,来协助当前程序的执行.换句话说,开启协程就是开启一个可以与程序并行的逻辑.可以用来控制运动.序列以及对象的行为. 二:Unity3d中的碰 ...
- EventBus (二) 使用详解——EventBus使用进阶
相关文章: 1.<EventBus使用详解(一)——初步使用EventBus> 2.<EventBus使用详解(二)——EventBus使用进阶> 一.概述 前一篇给大家装简单 ...
- 分享一个基于 Node.js 的 Web 开发框架 - Nokitjs
简介 Nokit 是一个简单易用的基于 Nodejs 的 Web 开发框架,默认提供了 MVC / NSP / RESTful 等支持,并提供对应项目模板.管理工具. 资源 GitHub https: ...
- trident介绍
(一)理论基础 很多其它理论以后再补充,或者參考书籍 1.trident是什么? Trident is a high-level abstraction for doing realtime comp ...
- C#的四个基本技巧
1.如果可能尽量使用接口来编程 .NET框架包括类和接口,在编写程序的时候,你可能知道正在用.NET的哪个类.然而,在这种情况下如果你用.NET支持的接口而不是它的类来编程时,代码会变得更加稳定.可用 ...
- easyui更换主题之后出现validatebox的验证提示信息显示跑偏的解决方案
在easyui中更换主题为非default的主题,有的主题会出现如下图所示的情况,验证提示信息的提示内容跑到了下面. 现在说下原因和解决方案: 原因:原因是easyui对某些主题没有进行这个样式的设置 ...
- Hadoop 基本架构
Hadoop 由两部分组成,分别是分布式文件系统和分布式计算框架 MapReduce. 其中分布式文件系统主要用于大规模数据的分布式存储,而 MapReduce 则构建在分布式文件系统之上,对存储在分 ...
- Kotlin(2): 优雅地扩展类的方法和属性
欢迎Follow我的GitHub, 关注我的CSDN. 个人博客: http://www.wangchenlong.org/, 最新内容. Kotlin由JetBrains公司推出, 是兼容Java的 ...