普通的最短路...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 下 Hadoop java api 问题

    1. org.apache.hadoop.security.AccessControlException: Permission denied: user=opsuser, access=WRITE, ...

  2. hdu 4704 Sum 费马小定理

    题目链接 求2^n%mod的值, n<=10^100000. 费马小定理 如果a, p 互质, 那么a^(p-1) = 1(mod p)  然后可以推出来a^k % p = a^(k%(p-1) ...

  3. A Byte of Python (1)安装和运行

    有两种方式构建软件设计:一种是把软件做得很简单以至于明显找不到缺陷:另一种是把它做得很复杂以至于找不到明显的缺陷. ——C.A.R. Hoare 获得人生中的成功需要的专注与坚持不懈多过天才与机会. ...

  4. Linux必学的60个命令【转载】

    Linux提供了大量的命令,利用它可以有效地完成大量的工 作,如磁盘操作.文件存  [转载地址]http://blog.chinaunix.net/uid-16728139-id-3154272.ht ...

  5. C# Convert an enum to other type of enum

    Sometimes, if we want to do convert between two enums, firstly, we may think about one way: var myGe ...

  6. arm中的ldr指令

    label .equ 0x53000000 ldr r0, label : 将0x53000000地址处的值放入r0中 ldr r0, =label : 将0x53000000付值给r0.

  7. 使用Protel99 SE 拼板的详细图解(新加队列粘贴方法)

    很多网友跟我沟通,提到我上次博文中的protel99se中做拼板图解过于简略,应大家的有求,重新修改了操作图示. 首先打开PCB文档.如图所示:电路板的原点并没有在边上,为了操作方便和规范,先把有点设 ...

  8. AssetManager中的路径参数不能包含"assets/"

    String path = “music/bg.mp3”: //正确的参数 //String path = “assets/music/bg.mp3”: //错误的参数 //String path = ...

  9. perl5 第十三章 Perl的面向对象编程

    第十三章 Perl的面向对象编程 by flamephoenix 一.模块简介二.Perl中的类三.创建类四.构造函数 实例变量 五.方法六.方法的输出七.方法的调用八.重载九.析构函数十.继承十一. ...

  10. python+opencv

    $cd numpy $ sudo python setup.py build $ sudo python setup.py installRunning from numpy source direc ...