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 ] << "\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

Gold

时间: 2024-10-07 05:16:03

BZOJ 3408: [Usaco2009 Oct]Heat Wave 热浪( 最短路 )的相关文章

3408: [Usaco2009 Oct]Heat Wave 热浪

3408: [Usaco2009 Oct]Heat Wave 热浪 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 67  Solved: 55[Submit][Status][Discuss] Description Input 第1行:4个由空格隔开的整数T,C,Ts,Te. 第2到第C+1行:第i+l行描述第i条道路.有3个由空格隔开的整数Rs,Re,Ci. Output 一个单独的整数表示Ts到Te的最小费用.数据保证至少存在一条道路. Sa

P3408: [Usaco2009 Oct]Heat Wave 热浪

水题,裸的最短路. const maxn=6200001; type link=^node; node=record t,d:longint; f:link; end; var n,m,s,i,j,u,v,w,max:longint; adj:array[0..3000] of link; f:array[0..1000000] of longint; d,val:array[0..3000] of longint; went:array[0..3000] of boolean; procedu

BZOJ 3407: [Usaco2009 Oct]Bessie&#39;s Weight Problem 贝茜的体重问题( dp )

01背包... ----------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #define rep( i , n ) for( int i = 0 ; i < n ; i++ ) #define clr( x , c ) m

P1339 [USACO09OCT]热浪Heat Wave

P1339 [USACO09OCT]热浪Heat Wave 题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for good eating but are not so adept at creating creamy delicious dairy products. Farmer John is leading the charge to delive

洛谷—— P1339 [USACO09OCT]热浪Heat Wave

P1339 [USACO09OCT]热浪Heat Wave 题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for good eating but are not so adept at creating creamy delicious dairy products. Farmer John is leading the charge to delive

3409: [Usaco2009 Oct]Barn Echoes 牛棚回声

3409: [Usaco2009 Oct]Barn Echoes 牛棚回声 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 57  Solved: 47[Submit][Status][Discuss] Description 奶牛们灰常享受在牛栏中哞叫,因为她们可以听到她们哞声的回音.虽然有时候并不能完全听到完整的回音.Bessie曾经是一个出色的秘书,所以她精确地纪录了所有的哞叫声及其回声.她很好奇到底两个声音的重复部份有多长. 输入两个字符串(

3407: [Usaco2009 Oct]Bessie&#39;s Weight Problem 贝茜的体重问题

3407: [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 48  Solved: 46[Submit][Status][Discuss] Description 贝茜像她的诸多姊妹一样,因为从约翰的草地吃了太多美味的草而长出了太多的赘肉.所以约翰将她置于一个及其严格的节食计划之中.她每天不能吃多过H(5≤日≤45000)公斤的干草.贝茜只能吃一整捆干草:当

DP经典 BZOJ 1584: [Usaco2009 Mar]Cleaning Up 打扫卫生

BZOJ 1584: [Usaco2009 Mar]Cleaning Up 打扫卫生 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 419  Solved: 278 Description 有N头奶牛,每头那牛都有一个标号Pi,1 <= Pi <= M <= N <= 40000.现在Farmer John要把这些奶牛分成若干段,定义每段的不河蟹度为:若这段里有k个不同的数,那不河蟹度为k*k.那总的不河蟹度就是所有段的不河蟹度的总和

BZOJ 2007 海拔(平面图最小割-最短路)

题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2007 题意:给出一个n*n的格子,那么顶点显然有(n+1)*(n+1)个.每两个相邻顶点之间有两条边,这两条边是有向的,边上有权值..左上角为源点,右下角为汇点,求s到t的最小割. 思路:很明显这是一个平面图,将其转化为最 短路.我们将s到t之间连一条边,左下角为新图的源点S,右上角区域为新图的终点T,并且为每个格子编号.由于边是有向的,我们就要分析下这条边应该是哪 个点向哪个点的边.