普通的最短路...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. C/C++ 结构体成员在内存中的对齐规则

    这几天在看王艳平的<windows 程序设计>,第5章讲解了MFC框架是怎么管理窗口句柄到窗口实例之间的映射,用到了两个类CPlex和CMapPtrToPtr,用于管理内存分配的类(避免因 ...

  2. centos6.5 升级python 到 python 2.7.11 安装 pip

    1.首先官方下载源码,然后安装(./configure,make all,make install,make clean,make distclean) 注意:需要先安装zlib-devel,open ...

  3. 手动修改VisualStudio IISExpress的配置

    <VisualStudio> <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}"> ...

  4. MyEclipse 8.5整合Git,并在Github上发布项目(转)

    下载Eclipse的git插件——EGit.下载网址http://download.eclipse.org/egit/updates-1.3/org.eclipse.egit-updatesite-1 ...

  5. beini破解无线

    软件介绍 当你的笔记本有无线网卡却不能上网的时刻,也许你会很焦急. 又或许你的隔壁就有无线网络可以接的时刻,但你却由于米有密码而不能上网.下面我将简介一款可以令你惊讶的软件,奶瓶 有了奶瓶以上疑问都可 ...

  6. Score(规律)

    Score Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submiss ...

  7. IntelliJ IDEA 14 注册码生成器

    IntelliJ IDEA 14 注册码生成器 文件为Java代码 自己编译运行里面的程序输入名称然后就生成注册码了工具:http://yun.baidu.com/s/1cZKsA部分工具生成的注册码 ...

  8. ;(function($,window,undefined){})(jQuery,window)详细解析————借助B5教程解析自己整理了一下

    在jquery插件中我们经常看到以下这段代码 ;(function ( $, window, document, undefined ){ //函数体内具体代码 })(jQuery, window,d ...

  9. Expected stackmap frame at this location

    使用eclipse,本来使用的是jdk1.7的,后来切换到jdk1.8版本就出现了这个问题,报错的Reason说的是Expected stackmap frame at this location,其 ...

  10. HDU 2023题解分析

    我想说这道题我还没弄明白我错哪了,交了20多遍一直都是Runtime Error,改了N次还是不对,后来搜了一下,说是数组开小了,又把数组开大,还不对,又改发现一个平均值求错,再改,还不对,洗洗睡吧. ...