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 ...
随机推荐
- Spark-GraphxAPI学习笔记
图的集合视图 graph包含三个基本的类集合视图: val vertices: VertexRDD[VD] val edges: EdgeRDD[ED] val triplets: RDD[EdgeT ...
- wife信号如何传播
方法一:像哈利波特一样穿墙而出 无论是wife信号还是广播信号本质上都属于电磁波.x光穿透力强所以可以穿透人体给体内照相,但是wife信号作为电磁波虽然也可以穿透墙而过,但是他的穿透能力实在是太弱了. ...
- Xcode插件推荐
deriveddata-exterminator: A magic button in Xcode to exterminate the current project's DerivedData d ...
- C# 语言规范_版本5.0 (第21章 附录C_参考资料)
A. 参考资料 Unicode 联合会.The Unicode Standard, Version 3.0(Unicode 标准 3.0 版).Addison-Wesley,Reading,Massa ...
- git linux 多工程部署及git默认端口更改
>> ssh-keygen -t rsa -C "your_email@youremail.com" print Generating public/private ...
- mybatis学习笔记三(关联关系)
学习mybatis的关联关系,主要注解在代码上,这里不做解释.配置文件一样的就不贴了 1.关联关系表创建(学生对应老师 多对一) 学生老师表 2.表对应的实体类 package com.home.en ...
- svn用Cornerstone上传项目丢失静态库.a问题的解决
最近电脑重装系统后,装上Cornerstone上传项目后,发现又有丢失.a文件的问题,这里说一下解决办法,打开Preferences-->Subversion-->General,将Use ...
- xml动态修改 dom4j修改
xml的动态修改需要传入的参数 xml的位置(tomcat中的发布位置).修改后的xml需要保存的位置(因为动态修改,所以建议和xml未修改前的位置相同).添加的节点的信息.或者修改的节点的信息 SA ...
- IntelliJ IDEA “Finds duplicated code”提示如何关闭
发现重复的代码这个提示真的很烦啊,我们怎么关闭他呢. 设置在这里: Settings -> Editor -> Inspections -> General -> Duplic ...
- MFC 刷新失效的Picture控件
问题描述:如在摄像头显示时,关闭摄像头,此时Picture控件仍然显示最后一帧图像,需要刷新掉,还原Picture控件.或者重复显示两张不同大小的图片时,第二张背景有第一张图片残留. 解决方法1:(最 ...