( ̄▽ ̄)"

//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. LWP::UserAgent介绍2

    #这个LWP::UserAgent一般要配合其他模块使用 #比如: #HTTP::Request #HTTP::Cookie #HTTP::Respose #HTTP::Status #LWP::Us ...

  2. python 基础学习4-with语句

    why use With? 有些事情需要事先进行设置,事后进行处理,with语句提供了一个很好的处理方式,例如文件读写处理,有时候可能忘记关闭文件,with可以很好地处理这种现象. with语句用来简 ...

  3. SVN常用命令积累

      一.SVN SW (repo 重定向) 服务器的IP地址或者URL变更,版本库服务器的IP也要修改,因为当初安装SVN URL没有使用别名,所以使用的人都要修改客户端的IP. 1.Windows ...

  4. 工艺成型及仿真、铸造工艺及仿真ProCAST软件入门认识介绍

    视频源:技术邻 关键词:ProCAST.工艺成型及仿真.铸造工艺及仿真 简介:ProCAST 软件是由美国 USE 公司开发的铸造过程的模拟软件采用基于有限元(FEM)的数值计算和综合求解的方法,对铸 ...

  5. 未知的生成错误 因为没有预加载,所以无法解析程序集 GalaSoft.MvvmLight

    使用wpf开发时,在ViewModel中引用了DevExpress注册的GalaSoft.MvvmLight命名空间,使用其ViewModelBase,在View界面中绑定事件时出现错误: 错误 13 ...

  6. 常用JavaScript字符串方法简述

    网址来源:http://www.html-js.com/article/JS-rookie-in-the-rookie-to-start-learning-to-fly-the-commonly-us ...

  7. Qml 定义 constant

    对于程序中一些常量如字符串, 实数等, C++中经常用的方法, 是定义全局常量: 或者把所有意义相近的常量用一个单例类收集起来. QML是类JSON的标识性语言, 使用js 语法去操作对象. 在QML ...

  8. mysql解决中文乱码问题

    安装文件 my.ini default-character-set=gbk 安装文件 db.opt default-character-set=gbkdefault-collation=gbk_chi ...

  9. 一行一行分析JQ源码学习笔记-04

    jquery添加方法和属性 jquery.fn=jquery.prototype ={ jquery版本 } construtor  指向修正 js源码中 fun  aaa(){} 会自动生成一句   ...

  10. 苹果dock效果

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...