普通的最短路...dijkstra水过..

------------------------------------------------------------------------------

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
 
#define rep( i , n ) for( int i = 0 ; i < n ; i++ )
#define clr( x , c ) memset( x , c , sizeof( x ) )
 
using namespace std;
 
const int maxn = 2500 + 5;
const int maxm = 6200 + 5;
const int inf = 0x3f3f3f3f;
 
struct edge {
int to , dist;
edge* next;
};
 
edge* pt , EDGE[ maxm << 1 ];
edge* head[ maxn ];
 
void edge_init() {
pt = EDGE;
clr( head , 0 );
}
 
void add( int u , int v , int d ) {
pt -> to = v;
pt -> dist = d;
pt -> next = head[ u ];
head[ u ] = pt++;
}
#define add_edge( u , v , d ) add( u , v , d ) , add( v , u , d )
 
struct node {
int x , d;
bool operator < ( const node &rhs ) const {
return d > rhs.d;
}
};
 
int d[ maxn ];
priority_queue< node > Q;
 
void dijkstra( int S ) {
clr( d , inf );
d[ S ] = 0;
Q.push( ( node ) { S , 0 } );
while( ! Q.empty() ) {
node o = Q.top();
Q.pop();
int x = o.x , dist = o.d;
if( dist != d[ x ] ) continue;
for( edge* e = head[ x ] ; e ; e = e -> next ) {
int to = e -> to;
if( d[ to ] > dist + e -> dist ) {
d[ to ] = dist + e -> dist;
Q.push( ( node ) { to , d[ to ] } );
}
}
}
}
 
inline int read() {
char c = getchar();
int res = 0;
while( ! isdigit( c ) ) c = getchar();
while( isdigit( c ) ) {
res = res * 10 + c - '0';
c = getchar();
}
return res;
}
 
int main() {
    freopen( "test.in" , "r" , stdin );
    
    int n = read() , m = read() , s = read() - 1 , t = read() - 1;
    edge_init();
    while( m-- ) {
    int u = read() - 1 , v = read() - 1 , d = read();
    add_edge( u , v , d );
    }
    dijkstra( s );
    cout << d[ t ] << "\n";
    
return 0;
}

------------------------------------------------------------------------------

3408: [Usaco2009 Oct]Heat Wave 热浪

Time Limit: 3 Sec  Memory Limit: 128 MB
Submit: 71  Solved: 59
[Submit][Status][Discuss]

Description

Input

 第1行:4个由空格隔开的整数T,C,Ts,Te.
 第2到第C+1行:第i+l行描述第i条道路.有3个由空格隔开的整数Rs,Re,Ci.

Output

    一个单独的整数表示Ts到Te的最小费用.数据保证至少存在一条道路.

Sample Input

7 11 5 4
2 4 2
1 4 3
7 2 2
3 4 3
5 7 5
7 3 3
6 1 1
6 3 4
2 4 3
5 6 3
7 2 1

Sample Output

7

HINT

Source

BZOJ 3408: [Usaco2009 Oct]Heat Wave 热浪( 最短路 )的更多相关文章

  1. 3408: [Usaco2009 Oct]Heat Wave 热浪

    3408: [Usaco2009 Oct]Heat Wave 热浪 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 67  Solved: 55[Subm ...

  2. [Usaco2009 Oct]Heat Wave 热浪(裸最短路径)

    链接:https://ac.nowcoder.com/acm/contest/1082/F来源:牛客网 题目描述 The good folks in Texas are having a heatwa ...

  3. P3408: [Usaco2009 Oct]Heat Wave 热浪

    水题,裸的最短路. ; type link=^node; node=record t,d:longint; f:link; end; var n,m,s,i,j,u,v,w,max:longint; ...

  4. BZOJ3408: [Usaco2009 Oct]Heat Wave 热浪

    最短路模板.选迪杰. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<alg ...

  5. BZOJ 3407: [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题( dp )

    01背包... ----------------------------------------------------------------------- #include<cstdio&g ...

  6. 洛谷 P1339 [USACO09OCT]热浪Heat Wave(最短路)

    嗯... 题目链接:https://www.luogu.org/problem/P1339 这道题是水的不能在水的裸最短路问题...这里用的dijkstra 但是自己进了一个坑—— 因为有些城市之间可 ...

  7. 【洛谷1339 [USACO09OCT]】热浪Heat Wave 图论+最短路

    AC代码 #include<bits/stdc++.h> using namespace std; const int MAXN=62000+10,INF=999999; struct E ...

  8. 洛谷—— P1339 [USACO09OCT]热浪Heat Wave

    P1339 [USACO09OCT]热浪Heat Wave 题目描述 The good folks in Texas are having a heatwave this summer. Their ...

  9. Luogu P1339 热浪Heat Wave

    Luogu P1339 热浪Heat Wave 裸·单源最短路. 但是! 有以下坑点: 算过复杂度发现Floyd跑不过去就不要用了. 如果建边是双向边,边的数组大小要开两倍! 考场上如果再把初始化的$ ...

随机推荐

  1. 转: Nodejs概述

    目录 简介 安装与更新 版本管理工具nvm 基本用法 REPL环境 异步操作 全局对象和全局变量 模块化结构 概述 核心模块 自定义模块 fs模块 Stream模式 http模块 实例:搭建一个HTT ...

  2. protel99_拼板详细图解

    首先打开PCB文档.如图所示,在PCB左下角放置一個坐標為X=0,Y=0的焊盤. 从下图看,为了方便电路板生产厂家的加工和焊接工厂的加工,拼版的方向是向上Y轴方向拼版. 接着为了在拼版过程中好对齐板边 ...

  3. (C#)Windows Shell 外壳编程系列6 - 执行

    原文(C#)Windows Shell 外壳编程系列6 - 执行 (本系列文章由柠檬的(lc_mtt)原创,转载请注明出处,谢谢-) 接上一节:(C#)Windows Shell 外壳编程系列5 - ...

  4. 利用CSS、JavaScript及Ajax实现图片预加载的三大方法(转)

    预加载图片是提高用户体验的一个很好方法.图片预先加载到浏览器中,访问者便可顺利地在你的网站上冲浪,并享受到极快的加载速度.这对图片画廊及图片占据很大比例的网站来说十分有利,它保证了图片快速.无缝地发布 ...

  5. asp.net js调用后台方法

    先前网上百度了很多 ,大致都一样 但是不太详细,总是不成功,然后试了很多,把经验发给大家看看 前台js function aa() { //这里可以写你要带的参数用隐藏域放起来 __doPostBac ...

  6. eclipse hibernate插件在线安装

    下面介绍下 关于在eclipse下如何在线安装插件 首先需要打开eclipse  点击 安装完成后,进入hibernate视图,在左侧窗口右键add configuration, 第一个name属性, ...

  7. 重启IIS报错:IIS 服务或万维网发布服务,或者依赖这 服务可能在启动期间发生错误或者已禁用

    参考文章: http://www.cnblogs.com/zengen/archive/2010/10/29/1864569.html 开启如下服务: Net.Msmq Listener Adapte ...

  8. 访问Tableau自带的PostgreSQL数据库

    突然发现公司Tableau服务器的数据库大小急剧增加,因此决定直接连上数据库排查.过程记录如下:最后发现有个http_requests 表体积巨大(7G),本来以为是数据缓存什么的.结果是日志问题o( ...

  9. [译]Stairway to Integration Services Level 12 - 高级日志配置

    介绍 本文中,我们将结合之前学习的时间冒泡,日志记录,以及复制模型.建立一个自定义的SSIS包日志模型. SSIS Task事件回顾    Reviewing SSIS Task Events 在做实 ...

  10. js 获取单项复选的值

    html: 单选框-----> 25岁以下 25~35岁 35~50岁 50岁以上 获值 var question1 = $('input:radio[name="radio" ...