普通的最短路...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. linux里source、sh、bash、./有什么区别

    在linux里,source.sh.bash../都可以执行shell script文件,那它们有什么不同吗? ----------- 1.source source a.sh 在当前shell内去读 ...

  2. 理解Python的with as语句

    简单的说, with open(filepath, 'wb') as file: file.write("something") 等价于: file = open(filepath ...

  3. (Problem 46)Goldbach's other conjecture

    It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...

  4. mybatis获取插入的语句主键(自增主键)

    <insert id="insertUser" parameterType="User"> <selectKey keyProperty=&q ...

  5. 文件上传 PHP

    参考http://www.w3school.com.cn/php/php_file_upload.asp 文件上传实际上是一个文件复制的过程  当我们选中一个文件之后  php默认的tmp文件夹中就有 ...

  6. 使用HISTCONTROL强制history忽略某条特定命令

    http://www.linuxnote.org/mandatory-use-of-histcontrol-ignore-a-certain-specific-command-history.html ...

  7. COB封装的优势

    随着固态照明技术的不断进步,COB(chip-on-board)封装技术得到越来越多的重视,由于COB光源有热阻低,光通量密度高,眩光少,发光均匀等特性,在室内外照明灯具中得到了广泛的应用,如筒灯,球 ...

  8. QT5程序发布dll依赖

    QT5 发布程序,太庞大了,QT4下,基本的也就20M左右 platforms目录是 对应X:\Qt\Qt5.3.2\5.3\mingw482_32\plugins\platforms 下的qmini ...

  9. NHibernate 的 ID 标识选择器

    在 Hibernate 中,每个对象需要一个标识 ID,通过这个标识 ID 建立对象与数据库中记录的对应关系. Nhibernate 提供了多种方式来建立这个 POID.基于不同的生成策略,可以选择更 ...

  10. java 面试 复习 II

    1  break  多重 循环跳出当前循环到上层循环再执行. 如若想跳出多重循环可以使用标号 2  byte,short,char都可以隐含转换为int.可以用在switch 表达式.long和str ...