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 ...
随机推荐
- php学习笔记——CSS缓存问题
PHP也没学多久,在工作中遇到了一个问题,先来记录一下. 问题描述: 同一项目里面的不同模块对应了不同的网站,但是两个网站用的文件名以是同一规范的,最后导致了两个网站css文件同名,在打开了网站A后去 ...
- nyoj 592 spiral grid(广搜)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=592 解决以下问题后就方便用广搜解: 1.将数字坐标化,10000坐标为(0,0),这样就 ...
- C#中对属性和字段的理解
字段 C#中很少提到全局变量的概念, 引入了字段一词来代替全局变量, 但也并不是这样简单的, 字段会比全局变量的使用更难理解, 使用上会简单, 初学者当做成员变量或者全局变量不会有什么影响, 随着使用 ...
- Unity3DGUI:Window
#pragma strictvar winRect:Rect=Rect(30,100,150,200);var windowShow:boolean=true;function OnGUI () { ...
- Redis 数据序列化方法 serialize, msgpack, json, hprose 比较
最近弄 Redis ,涉及数据序列化存储的问题,对比了:JSON, Serialize, Msgpack, Hprose 四种方式 1. 对序列化后的字符串长度对比: 测试代码: $arr = [0, ...
- socket编程之TCP/UDP
目标: 1.编写TCP服务端客户端,实现客户端发送数据,服务端接收打印 2.采用OOP方式编写TCP服务端客户端,实现客户端发送数据,服务端添加时间戳,返回给客户端 3.采用OOP方式编写UDP服务端 ...
- git add -f
git add -f 添加已被 .gitignore 忽略的文件/文件夹
- Leetcode 解题报告
347. Top K Frequent Elements Given a non-empty array of integers, return the k most frequent element ...
- 通过一个表的id同时查询多个表的数据
'select c.字段名,x.字段名 as 改为新的显示名,x.字段名 from 表名1 b,表名2 c,表名3 x where b.字段id=' . $id . ' and b.`字段id`=c. ...
- mob.com Android studio 配置环境