Lightoj 1019 - Brush (V)
算出从点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)的更多相关文章
- Light OJ 1019 - Brush (V)(图论-dijkstra)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1019 题目大意:Tanvir想从节点1的位置走到节点n的位置, 输出最短距离, ...
- Lightoj 1016 - Brush (II)
After the long contest, Samee returned home and got angry after seeing his room dusty. Who likes to ...
- lightoj 1019
裸的最短路 dijkstra #include<cstdio> #include<string> #include<cstring> #include<ios ...
- lightOJ 1017 Brush (III) DP
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道 ...
- LightOJ 1017 - Brush (III) 记忆化搜索+细节
http://www.lightoj.com/volume_showproblem.php?problem=1017 题意:给出刷子的宽和最多横扫次数,问被扫除最多的点是多少个. 思路:状态设计DP[ ...
- [LightOJ 1018]Brush (IV)[状压DP]
题目链接:http://lightoj.com/volume_showproblem.php? problem=1018 题意分析:平面上有不超过N个点,如今能够随意方向划直线将它们划去,问:最少要划 ...
- Lightoj 1018 - Brush (IV)
1018 - Brush (IV) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Muba ...
- Lightoj 1017 - Brush (III)
1017 - Brush (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Sam ...
- light oj 1019【最短路模板】
1019 - Brush (V) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Tanvir r ...
随机推荐
- 【HIHOCODER 1320】压缩字符串(区间DP)
描述 小Hi希望压缩一个只包含大写字母'A'-'Z'的字符串.他使用的方法是:如果某个子串 S 连续出现了 X 次,就用'X(S)'来表示.例如AAAAAAAAAABABABCCD可以用10(A)2( ...
- idea 中使用 出现 svn: E155036
在idea中使用svn checkout时 svn出现如上错误. 原因本地的工作副本太旧.command line进入本地工作副本的根目录,执行svn upgrade后 重启idea就可以了.
- STM32F407 串口通信实验 视频第27节 个人笔记
前言 第26节也是串口,笔记链接在此:https://www.cnblogs.com/YuQiao0303/p/10019362.html github地址:https://github.com/Yu ...
- spring的IOC入门案例
步骤: 一,导入jar 二,创建类,在类里创建方法 三,创建Spring配置文件,配置创建类 四,写代码测试对象创建
- mongodb 的创建和使用
1. sudo apt-get install mongodb 2. 登陆数据库: mongo, 3. 创建数据库:use dbname 4. 插入数据: db.dbname.insert({&quo ...
- 【java基础 3】树形结构数据呈现的递归算法实现
一.基本概况 在我的项目中,常常会用到树形结构的数据,最为明显的就是左边菜单栏,类似于window folder一样的东西. 而我之前一直是借助前端封装好的ZTree等工具实现展示,而后台则通常使用递 ...
- Robot Framework中的未解之谜
今天在写测试用例的时候偶然发现了一个问题: 一.看脚本逻辑上没有问题,但是在引用变量的时候不能成功引用,脚本截图如下: 这个是关键字A的截图,没有参数. 此时在case中引用${phonesign}和 ...
- hdu 2579
#include<stdio.h> #include<queue> #include<iostream> #include<string.h> #inc ...
- 手动扩大栈内存,让AC无忧
http://blog.csdn.net/shahdza/article/details/6586430 还在因为 怕 g++ 提交时间很慢,但是用C++ 交又怕栈溢出??? 我们都知道,如果代码里有 ...
- 匿名函数--lambda函数
匿名函数 匿名函数:为了解决一些功能很简单的需求而设计的一句话函数 (python对匿名函数支持有限,只有一些简单的条件下可以用匿名函数) 匿名函数固定格式: func = lambda *args: ...