POJ 3268Silver Cow Party (迪杰斯特拉)
来源:互联网 发布:java入门到精通4 pdf 编辑:程序博客网 时间:2024/06/05 10:39
题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=66569#problem/D
代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn=1005;int maps1[maxn][maxn];int maps2[maxn][maxn];int dis1[maxn];int dis2[maxn];int book[maxn];int n,m,x;int dij(int maps[maxn][maxn],int dis[maxn]){ memset(book,0,sizeof(book)); book[x]=1; for(int i=1;i<=n;i++) { dis[i]=maps[x][i]; } int temp; for(int i=1;i<=n;i++) { int minn=1e9; for(int j=1;j<=n;j++) { if(book[j]==0&&dis[j]<minn) { minn=dis[j]; temp=j; } } book[temp]=1; for(int v=1;v<=n;v++) { if(book[v]==0&&dis[v]>dis[temp]+maps[temp][v]) { dis[v]=dis[temp]+maps[temp][v]; } } } for(int i=1;i<=n;i++) { //printf("%d ",dis[i]); }}int main(){ scanf("%d%d%d",&n,&m,&x); for(int i=1;i<maxn;i++) { for(int j=1;j<maxn;j++) { maps1[i][j]=1e9; maps2[i][j]=1e9; } } for(int i=0;i<m;i++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); maps1[a][b]=c; maps2[b][a]=c; } dij(maps1,dis1); dij(maps2,dis2); int ans=0; for(int i=1;i<=n;i++) { if(i==x) continue; ans=max(ans,dis1[i]+dis2[i]); } printf("%d\n",ans);}
两个dij 跑一下。不敢相信的1A。
0 0
- POJ 3268Silver Cow Party (迪杰斯特拉)
- poj 3268 Silver Cow Party(迪杰斯特拉)
- poj 3268 Silver Cow Party
- POJ 3268 Silver Cow Party
- poj 3268 Silver Cow Party
- POJ 3268 Silver Cow Party
- POJ 3268 Silver Cow Party
- POJ-3268-Silver Cow Party
- poj 3268 Silver Cow Party
- poj 3268 Silver Cow Party
- POJ-3268-Silver Cow Party
- poj 3268--Silver Cow Party
- POJ 3268 Silver Cow Party
- POJ 3268 Silver Cow Party
- POJ 3268 Silver Cow Party
- POJ 3268 Silver Cow Party
- POJ-3268 Silver Cow Party
- poj 3268 Silver Cow Party
- leetcode笔记—生成最大的 数组Create Maximum Number
- 函数式编程
- java设计模式-组合模式
- Android Home按键的监听与屏蔽方式
- 提交表单用ajax判断登录正确并跳转页面的方法
- POJ 3268Silver Cow Party (迪杰斯特拉)
- 2016.5.25笔记
- C++作业6
- Python3 迭代器与生成器
- HDU 5444 Elven Postman
- 文章标题
- 手把手教学 git
- Android-分辨率以及dip(dp)、dpi、ppi、px、sp、pt说明
- NoSQL 与大数据