算出从点1到点n的最短路径。

/* ***********************************************
Author :guanjun
Created Time :2016/6/23 22:58:19
File Name :1019.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
int dis[][];
int n,m;
int lowcost[];
int vis[];
int dij(){
cle(vis);
vis[]=;
memset(lowcost,INF,sizeof lowcost);
for(int i=;i<=n;i++)lowcost[i]=dis[][i];
lowcost[]=;
int k,Min;
for(int i=;i<=n;i++){
Min=INF;
for(int j=;j<=n;j++){
if(lowcost[j]<Min&&!vis[j])Min=lowcost[j],k=j;
}
if(Min==INF)break;
vis[k]=;
for(int j=;j<=n;j++){
if(lowcost[j]>lowcost[k]+dis[k][j]&&!vis[j])
lowcost[j]=lowcost[k]+dis[k][j];
}
}
return lowcost[n];
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int T,x,y;
ll z;
cin>>T;
for(int t=;t<=T;t++){
cin>>n>>m;
memset(dis,INF,sizeof dis);
for(int i=;i<=m;i++){
cin>>x>>y>>z;
if(dis[x][y]>z)dis[y][x]=dis[x][y]=z;
}
int ans=dij();
if(ans==INF){
printf("Case %d: Impossible\n",t);
}
else printf("Case %d: %d\n",t,ans); }
return ;
}

Lightoj 1019 - Brush (V)的更多相关文章

  1. Light OJ 1019 - Brush (V)(图论-dijkstra)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1019 题目大意:Tanvir想从节点1的位置走到节点n的位置, 输出最短距离, ...

  2. Lightoj 1016 - Brush (II)

    After the long contest, Samee returned home and got angry after seeing his room dusty. Who likes to ...

  3. lightoj 1019

    裸的最短路 dijkstra #include<cstdio> #include<string> #include<cstring> #include<ios ...

  4. lightOJ 1017 Brush (III) DP

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道 ...

  5. LightOJ 1017 - Brush (III) 记忆化搜索+细节

    http://www.lightoj.com/volume_showproblem.php?problem=1017 题意:给出刷子的宽和最多横扫次数,问被扫除最多的点是多少个. 思路:状态设计DP[ ...

  6. [LightOJ 1018]Brush (IV)[状压DP]

    题目链接:http://lightoj.com/volume_showproblem.php? problem=1018 题意分析:平面上有不超过N个点,如今能够随意方向划直线将它们划去,问:最少要划 ...

  7. Lightoj 1018 - Brush (IV)

    1018 - Brush (IV)    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Muba ...

  8. Lightoj 1017 - Brush (III)

    1017 - Brush (III)    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Sam ...

  9. light oj 1019【最短路模板】

    1019 - Brush (V) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Tanvir r ...

随机推荐

  1. HDU 1166 排兵布阵(线段树单点更新)

    题意: 给定n个兵营的士兵初始值, 然后有最多40000个操作: 操作一共有两种, 一个是查询给定[a,b]区间兵营的士兵总和. 另一个是增加/减少指定兵营的士兵数目. 输出每次查询的值. 分析: 线 ...

  2. Android开发——遍历读写U盘、SD卡等外部存储

    1.首先需要得到挂载在手机上的有哪些盘符 String[] result = null; StorageManager storageManager = (StorageManager)getSyst ...

  3. django1.11 启动错误:Generator expression must be parenthesized

    错误信息: Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0 ...

  4. exports和moudle. exports

    http://zihua.li/2012/03/use-module-exports-or-exports-in-node/ https://github.com/seajs/seajs/issues ...

  5. Linux 下Python2.7解决list打印中文字符问题

    在写一个爬取智联招聘数据的爬虫中,将所需内容匹配到后打印出现了utf-8字符,并没有出现中文字符. 例如: >>>listnine = ['梨', '橘子', '苹果', '香蕉'] ...

  6. CodeForces - 43B Letter

    字符串的处理 统计已有字符的个数 和需求字符比较 #include <iostream> #include <stdio.h> #include <string.h> ...

  7. [NOIP1999] 普及组

    回文数 /*By SilverN*/ #include<algorithm> #include<iostream> #include<cstring> #inclu ...

  8. delightful world--计蒜客(DFS)

    http://nanti.jisuanke.com/t/11067 题目大意: 给你一个n和m  下面是m个字符串和k   每一字符串的长度是n  你要找一个串跟每一个串匹配  有k个字符是和这个串相 ...

  9. hdu 3237

    dp 状态压缩 #include <cstdio> #include <cstdlib> #include <cmath> #include <map> ...

  10. spring-security 理解 笔记 介绍以及使用(持续更新)

    本人经过2周的学习,成功搭建了认证服务器,资源服务器和客户端 .下面是本人对 oauth2的理解,以及spring-security的使用,如果理解错误的地方,还望指正. 现在代码有点凌乱,过段时间会 ...