( ̄▽ ̄)"

//dijkstra算法;
//这题建邻接矩阵的时候有坑(先读入边后读入点),还有重边;
#include<iostream>
#include<cstdio>
using namespace std;
const int INF=10e7;
const int MAXN=2010;
int k,minn;
int cost[MAXN][MAXN];
int lowcost[MAXN];
bool vis[MAXN]; void dij(int n,int start)
{
for(int i=1;i<=n;i++)
{
lowcost[i]=INF;vis[i]=0;
}
lowcost[start]=0;
for(int i=1;i<=n;i++)
{
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]&&cost[k][i]>=0&&lowcost[k]+cost[k][i]<lowcost[i])
{
lowcost[i]=lowcost[k]+cost[k][i];
}
}
}
} int main()
{
int t,n,a,b,c;
while(scanf("%d%d",&t,&n)!=EOF)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j) cost[i][j]=0;
else cost[i][j]=INF;
}
}
for(int i=1;i<=t;i++)
{
scanf("%d%d%d",&a,&b,&c);
if(c<cost[a][b])
{ cost[a][b]=c; cost[b][a]=c; }
}
dij(n,n);
printf("%d\n",lowcost[1]);
}
return 0;
}

POJ 2387 Til the Cows Come Home(dij+邻接矩阵)的更多相关文章

  1. POJ.2387 Til the Cows Come Home (SPFA)

    POJ.2387 Til the Cows Come Home (SPFA) 题意分析 首先给出T和N,T代表边的数量,N代表图中点的数量 图中边是双向边,并不清楚是否有重边,我按有重边写的. 直接跑 ...

  2. POJ 2387 Til the Cows Come Home (图论,最短路径)

    POJ 2387 Til the Cows Come Home (图论,最短路径) Description Bessie is out in the field and wants to get ba ...

  3. POJ 2387 Til the Cows Come Home

    题目链接:http://poj.org/problem?id=2387 Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K ...

  4. POJ 2387 Til the Cows Come Home Dijkstra求最短路径

    Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to get as much s ...

  5. POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)

    传送门 Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 46727   Acce ...

  6. 怒学三算法 POJ 2387 Til the Cows Come Home (Bellman_Ford || Dijkstra || SPFA)

    Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 33015   Accepted ...

  7. POJ 2387 Til the Cows Come Home (最短路 dijkstra)

    Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Bessi ...

  8. POJ 2387 Til the Cows Come Home 【最短路SPFA】

    Til the Cows Come Home Description Bessie is out in the field and wants to get back to the barn to g ...

  9. POJ 2387 Til the Cows Come Home (最短路径 模版题 三种解法)

    原题链接:Til the Cows Come Home 题目大意:有  个点,给出从  点到  点的距离并且  和  是互相可以抵达的,问从  到  的最短距离. 题目分析:这是一道典型的最短路径模版 ...

随机推荐

  1. &reg 不需要显示为商标符的做法

    若url中有参数reg,则把&reg 变为 &reg

  2. 训练[2]-DFS

    题目A: 题目B[https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pro ...

  3. linux-c/c++调试利器gdb、ddd小试

    linux-c/c++调试利器gdb.ddd小试 原文链接: http://deepfuture.iteye.com/blog/749148 博客分类: C++/C/lisp CC++C#LinuxU ...

  4. kinect2 body joints 的25个点

    JointType_SpineBase    = 0,        JointType_SpineMid    = 1,        JointType_Neck    = 2,        J ...

  5. js变量,语句

  6. 定时器 QuartZ Cron表达式

    CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表. CronT ...

  7. 第七十五节,CSS表格与列表

    CSS表格与列表 学习要点: 1.表格样式 2.列表样式 3.其他功能 一.表格样式 表格有五种独有样式,样式表如下:             属性               值           ...

  8. iOS开发运行时总是显示4s的尺寸

    今天新建了一个工程运行时,总是显示4s的尺寸,上面有一片黑,如下图所示: 解决方法:检查启动图片,没有包含6和6plus的启动图片,添加上启动图片时运行正常:

  9. GOPS 2016全球运维大会 • 北京站概况

    GOPS 2016全球运维大会上海站已圆满落幕,错过上海站的朋友或许会感到一些遗憾,但是不用担心,在12月16日,GOPS 2016全球运维大会 • 北京站将隆重召开,错过上海在的朋友可以赶上北京站哦 ...

  10. Java 反射 调用私有域和方法(setAccessible)

    Java 反射 调用私有域和方法(setAccessible) @author ixenos AccessibleObject类 Method.Field和Constructor类共同继承了Acces ...