算出从点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. manjaro xfce 18.0 踩坑记录

    manjaro xfce 18.0 踩坑记录 1 简介1.1 Manjaro Linux1.2 开发桌面环境2 自动打开 NumLock3 系统快照3.1 安装timeshift3.2 使用times ...

  2. LaTeX模板

    学校linux机子根本跑不动libreoffice,wps没有公式,只好上LaTeX了. 先 beamer: 需要安装firasans和firamono字体,思源黑体SC \documentclass ...

  3. Hibernate分页查询报错

    不知道什么原因,就是这里报错的

  4. ZOJ 3824 Fiber-optic Network

    Fiber-optic Network Time Limit: 15000ms Memory Limit: 262144KB This problem will be judged on ZJU. O ...

  5. bzoj 3772 精神污染 主席树+dfs序

    精神污染 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 637  Solved: 177[Submit][Status][Discuss] Descri ...

  6. 【NOIP模拟】数字对(RMQ,二分)

    题意:小H是个善于思考的学生,现在她又在思考一个有关序列的问题. 她的面前浮现出一个长度为n的序列{ai},她想找出一段区间[L, R](1 <= L <= R <= n). 这个特 ...

  7. windows7 下安装使用memcached(二)

    Memcached 安装使用 本地环境:Windows7 64位web环境:wamp集成环境,php版本:PHP Version 7.1.17 学习参考网站: RUNOOB.COM官网  http:/ ...

  8. python学习之-- 面向对象

    面向对象(简写:OOP) 面向对象编程定义:利用类和对象来创建各种模型,来实现对真实世界的描述. 优点:使程序更容易理解和维护以及扩展代码. 类定义:用来描述具有相同的属性和方法的对象的集合.(简单讲 ...

  9. 洛谷——P2256 一中校运会之百米跑

    P2256 一中校运会之百米跑 题目背景 在一大堆秀恩爱的**之中,来不及秀恩爱的苏大学神踏着坚定(?)的步伐走向了100米跑的起点.这时苏大学神发现,百米赛跑的参赛同学实在是太多了,连体育老师也忙不 ...

  10. Edit Distance(动态规划,难)

    Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...