POJ 3268 Silver Cow Party(dij+邻接矩阵)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std; const int INF=10e8;
const int MAXN=1010; int k,minn;
int cost[MAXN][MAXN],lowcost[MAXN],lc[MAXN];
bool vis[MAXN]; void Reverse(int n,int cost[][MAXN])
{
int t;
for(int i=1;i<=n;i++)
{
for(int j=1;j<i;j++)
{
t=cost[i][j];
cost[i][j]=cost[j][i];
cost[j][i]=t;
}
}
} void dij(int n,int st)
{
for(int i=1;i<=n;i++)
lowcost[i]=INF,vis[i]=0;
lowcost[st]=0;
for(int j=1;j<=n;j++)
{
k=-1,minn=INF;
for(int i=1;i<=n;i++)
if(!vis[i]&&lowcost[i]<minn)
{ minn=lowcost[i]; k=i; }
if(k==-1) break;
vis[k]=1;
for(int i=1;i<=n;i++)
if(!vis[i]&&lowcost[k]+cost[k][i]<lowcost[i])
lowcost[i]=lowcost[k]+cost[k][i];
}
} int main()
{
int n,m,x;
scanf("%d%d%d",&n,&m,&x);
int a,b,t;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cost[i][j]=(i==j)?0:INF;
while(m--)
{
scanf("%d%d%d",&a,&b,&t);
cost[a][b]=t;
}
dij(n,x);
for(int i=1;i<=n;i++)
lc[i]=lowcost[i];
Reverse(n,cost);
dij(n,x);
int maxi=0;
for(int i=1;i<=n;i++)
{
lc[i]+=lowcost[i];
if(lc[i]>maxi)
maxi=lc[i];
}
printf("%d\n",maxi);
return 0;
}
POJ 3268 Silver Cow Party(dij+邻接矩阵)的更多相关文章
- 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 (双向dijkstra)
题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
- POJ 3268 Silver Cow Party 最短路
原题链接: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:65536KB 64bit IO Format:%I64d & %I64u Su ...
- Poj 3268 Silver cow party 迪杰斯特拉+反向矩阵
Silver cow party 迪杰斯特拉+反向 题意 有n个农场,编号1到n,每个农场都有一头牛.他们想要举行一个party,其他牛到要一个定好的农场中去.每个农场之间有路相连,但是这个路是单向的 ...
- 图论 ---- spfa + 链式向前星 ---- poj 3268 : Silver Cow Party
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12674 Accepted: 5651 ...
- DIjkstra(反向边) POJ 3268 Silver Cow Party || POJ 1511 Invitation Cards
题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. PO ...
- 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 ...
随机推荐
- js分页模板
/** *参数说明: *currentPage:当前页数 *countPage:总页数 *changeMethod:执行java后台代码的js函数,即是改变分页数据的js函数 */ function ...
- LoadLibraryW 参数问题
error C2664: "LoadLibraryW": 不能将参数1 从"const char [8]"转换为"LPCWSTR" 右击工程 ...
- shrio初体验(1)
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #e6427a } p.p2 { margin: 0.0px 0 ...
- 【Android-UI】包含多个子View时触发父节点的焦点事件
今天遇到个问题: 在 LinearLayout 中添加了好几个其他视图 View 之后,点击时不能获得焦点,导致绑定的 onClick 事件不能触发. 解决办法: 对 LinearLayout 添加属 ...
- Java 并发 线程的生命周期
Java 并发 线程的生命周期 @author ixenos 线程的生命周期 线程状态: a) New 新建 b) Runnable 可运行 c) Running 运行 (调用 ...
- Nginx redirect
if ($host != 'www.xxxxx.com' ) { rewrite ^/(.*)$ http://www.xxxx.com/$1 permanent; }
- 取消a标签在移动端点击时的背景颜色
一.取消a标签在移动端点击时的蓝色 -webkit-tap-highlight-color: rgba(255, 255, 255, 0); -webkit-user-select: none; -m ...
- OGC 的WCS WFS 及WMS 服务
OGC--Open Geospatial Consortium--开放地理信息联盟,是一个非盈利的志愿的国际标准化组织,引领着空间地理信息标准及定位基本服务的发展目前在空间数据互操作领域,基于公共接口 ...
- removeObjectAtIndex
CGFloat lableW = (baseViewWidth - 2)/3;// dcj20150724,减2是为了解决字体模糊的问题,因为设置了边框. 原因是下面引起的 titleview.lay ...
- java的基础语法