( ̄▽ ̄)"

//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. 使用MyEclipse构建MAVEN项目

    这里用的是MyEclpise的自带的MAVEN插件.Maven最好配置成你自己安装的那个,MyEclipse自带会有些许Bug.用nexus代理Maven的中央仓库,setting.xml的配置文件修 ...

  2. setAction方法 Snackbar 右侧按钮可以被点击并处理一些事件

    从数据库同一记录取得的字段所组装成的对象应该是同一个对象,然后由不同的Session从数据库同一条记录上分别取得对象,它们的内存地址是不一样的. 一般来说,常见的数字加密方式都可以分为两类,即对称加密 ...

  3. 滚动动画animate-scroll扩展

    原动画库地址:animate-scroll 扩展动画库下载地址:animate-scroll-ext 由于项目需要,对animate-scroll进行扩展,扩展后修改或增加了以下几点: 对原动画库进行 ...

  4. python_批量修改文件名

    1.在movies文件夹下面的所有文件前面都加上[可可可可] #coding:utf-8 import os movie_name = os.listdir('./movies') for temp ...

  5. 黑帽么metasploit

    .Metasploit框架介绍Metasploit升级更新 Metasploit端口扫描 Metasploit SMB 获取系统信息 Metasploit 服务识别 Metasploit 密码嗅探 M ...

  6. 《JavaScript高级程序设计》读书笔记 ---Array 类型

    除了Object 之外,Array 类型恐怕是ECMAScript 中最常用的类型了.而且,ECMAScript 中的数组与其他多数语言中的数组有着相当大的区别.虽然ECMAScript 数组与其他语 ...

  7. AIDL机制实现进程间的通讯实例

    转载自:http://blog.csdn.net/cjjky/article/details/7562652 ======================================= 在Andr ...

  8. Arduino使用注意问题及编程相关

    1.Arduino的概念 arduino是一款便捷灵活方便上手的开源电子原型平台,包含硬件(各种型号的arduino板)和软件(arduino IDE), 是一个基于开放原始码的软硬件平台,构建于开放 ...

  9. Linux系统编程初探系列之一:文件编程

    系统函数 int creat(const char* filename,mode_t mode) filename:需要创建的文件名(包含路径,缺省为当前路径) mode:创建模式 常见的创建模式有: ...

  10. const形参与非const形参

    在程序设计中我们会经常调用函数,调用函数就会涉及参数的问题,那么在形参列表中const形参与非const形参对传递过来的实参有什么要求呢? 先来看一个简单的例子: #include <iostr ...