• 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

  • 相关阅读:
    Winform控件Enable=false显示优化
    request 报错The remote server returned an error: (415) Unsupported Media Type.
    InvalidArgument=Value of '1' is not valid for 'index'
    Redis学习笔记#12 Redis Cluster 集群
    centos7安装docker
    Redis学习笔记#11 关于key的建议
    Redis学习笔记#10 lua脚本,整合springboot调用
    ActiveMQ学习笔记#1
    SpringBoot学习笔记#2 具体化配置文件
    SpringBoot学习笔记#1 创建一个RESTful Web服务
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/4575799.html
Copyright © 2020-2023  润新知