• BZOJ 3408: [Usaco2009 Oct]Heat Wave 热浪( 最短路 )


    普通的最短路...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 ] << " ";
        
    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

  • 相关阅读:
    java基础之多线程一:概述
    java基础之io流总结四:字符流读写
    java基础之io流总结三:字节流读写
    java基础之io流总结二:File类基本应用
    java基础之io流总结一:io流概述
    java基础之集合:List Set Map的概述以及使用场景
    java基础之集合长度可变的实现原理
    HDU 4770 Lights Against Dudely 暴力枚举+dfs
    HDU 4771 BFS + 状压
    Codeforces Round #269 (Div. 2) D
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/4575799.html
Copyright © 2020-2023  润新知