题目链接:http://poj.org/problem?id=2387

题目大意:起点一定是1,终点给出,然后求出1到所给点的最短路径。

注意的是先输入边,在输入的顶点数,不要弄反哦~~~

 #include <iostream>
#include <cstdio>
using namespace std;
int map[][],Min,node[],vis[],t,q;
const int INF=; void set()
{
for (int i=; i<=; i++)
{
node[i]=INF;
vis[i]=;
for (int j=; j<=; j++)
map[i][j]=INF;
}
} int dijkstra(int m)
{
int tm=m;
vis[m]=;
node[m]=;
for (int k=; k<=q; k++)
{
Min=INF;
for (int i=; i<=q; i++)
if (!vis[i])
{
if (node[i]>map[tm][i]+node[tm])
{
node[i]=map[tm][i]+node[tm];
//cout<<map[tm][i]<<" "<<node[i]<<endl;
}
if (Min>node[i])
{
//cout<<Min<<endl;
Min=node[i];
m=i;
}
}
vis[m]=;
tm=m;
}
return Min;
} int main ()
{
int n;
//memset(map,0,sizeof(map));
while (~scanf("%d%d",&t,&n))
{
q=;
set();
while (t--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if (q<a)
q=a;
else if (q<b)
q=b;
if (map[a][b]>c)
{
map[a][b]=map[b][a]=c;
}
}
dijkstra(n);
printf("%d\n",node[]);
}
return ;
}

poj 2387 Til the Cows Come Home(dijkstra算法)的更多相关文章

  1. 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 ...

  2. POJ 2387 Til the Cows Come Home (Dijkstra)

    传送门:http://poj.org/problem?id=2387 题目大意: 给定无向图,要求输出从点n到点1的最短路径. 注意有重边,要取最小的. 水题..对于无向图,从1到n和n到1是一样的. ...

  3. Poj 2387 Til the Cows Come Home(Dijkstra 最短路径)

    题目:从节点N到节点1的求最短路径. 分析:这道题陷阱比较多,首先是输入的数据,第一个是表示路径条数,第二个是表示节点数量,在 这里WA了四次.再有就是多重边,要取最小值.最后就是路径的长度的最大值不 ...

  4. 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 ...

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

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

  6. POJ 2387 Til the Cows Come Home

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

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

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

  8. 怒学三算法 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 ...

  9. 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 ...

随机推荐

  1. C/S结构

    C/S结构 编辑 同义词 C/S架构一般指C/S结构 C/S 结构,即大家熟知的客户机和服务器结构.它是软件系统体系结构,通过它可以充分利用两端硬件环境的优势,将任务合理分配到Client端和Serv ...

  2. spring cloud 之 客户端负载均衡 Ribbon

    一.负载均衡 负载均衡(Load Balance): 建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽.增加吞吐量.加强网络数据处理能力.提高网络的灵活性和可用性.其意 ...

  3. 【Python】python-内置常量

    引言 Python的内置常量不多,只有6个,分别是True.False.None.NotImplemented.Ellipsis.__debug__ 一.True 1.True是bool类型用来表示的 ...

  4. 【bzoj1029】[JSOI2007]建筑抢修 贪心+堆

    题目描述 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者.但是T部落的基地里已经有N个建筑设施受到了严重的损伤,如果不尽快修复的话,这些建 ...

  5. Luogu1053 NOIP2005篝火晚会

    首先造出所要求的得到的环.如果将位置一一对应上,答案就是不在所要求位置的人数.因为显然这是个下界,并且脑补一下能构造出方案达到这个下界. 剩下的问题是找到一种对应方案使错位数最少.可以暴力旋转这个环, ...

  6. POJ3678:Katu Puzzle——题解

    http://poj.org/problem?id=3678 总觉得这题比例题简单. 设a为x取0的点,a+n为x取1的点. 我们还是定义a到b表示取a必须取b. 那么我们有: 当AND: 1.当c= ...

  7. c++ linux 判断string是中文的 or 英文的 字符串。

    #include <iostream> #include <string.h> #include <stdio.h> #include <stdlib.h&g ...

  8. 关于xml文件头部xmlsn

    样本: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://ww ...

  9. 负载均衡配置(基于Nginx)

    以下是基于nginx进行负载均衡配置的流程: 服务器配置如下: 1.  安装nginx的服务器:192.168.1.1 2.  nginx配置负载均衡位置及端口:192.168.1.1 80端口 3. ...

  10. HDU1815 2-sat+二分

    Building roads Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...