BZOJ 3408 Usaco Heat Wave

裸的最短路题目。
写一手Dijstra算法很舒服

#include <iostream>
#include <queue>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#define Heap pair<int,int>
using namespace std;
priority_queue< Heap,vector<Heap>,greater<Heap> > s;
const int MAXN=20005;
struct node{
    int u,v,w,next;
    node() {}
    node(int _u,int _v,int _w,int _next){
        u = _u,v = _v, w = _w,next = _next;
    }
}G[MAXN];
int n,m,start,end,Count,head[MAXN],dis[MAXN];
 
void AddEdge(int u,int v,int w){
    G[Count] = node(u,v,w,head[u]);
    head[u] = Count++;
}
 
void Dij(int x){
    for(int i=1;i<=n;i++) dis[i]=999999999;
    dis[x] = 0;
    s.push(make_pair(dis[x],x));
    while( !s.empty() ){
        Heap N = s.top();
        s.pop();
        int fuck = N.second;
        if(dis[fuck]!=N.first) continue;
        for(int e = head[fuck];e != -1;e=G[e].next){
            int v =G[e].v;
            int w =G[e].w;
            if(dis[fuck]+w<dis[v]){
                dis[v] = dis [fuck] + w;
                s.push(make_pair(dis[v],v));
            }
        }
    }
    printf("%d\n",dis[end]);
    return;
}
 
int main(){
    memset(head,-1,sizeof(head));
    scanf("%d%d%d%d",&n,&m,&start,&end);
    for(int i=1;i<=m;i++){
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        AddEdge(x,y,z);
        AddEdge(y,x,z);
    }  
    Dij(start);
    return 0;
}
时间: 2024-10-12 20:30:16

BZOJ 3408 Usaco Heat Wave的相关文章

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

普通的最短路...dijkstra水过.. ------------------------------------------------------------------------------ #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<queue> #define rep( i , n ) for( int i =

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

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

[BZOJ 1652][USACO 06FEB]Treats for the Cows 题解(区间DP)

[BZOJ 1652][USACO 06FEB]Treats for the Cows Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a given

洛谷 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 deliver plenty of ice cold nutritiou

luogu 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 deliver plenty of ice cold nutritiou

bzoj 3298: [USACO 2011Open]cow checkers -- 数学

3298: [USACO 2011Open]cow checkers Time Limit: 10 Sec  Memory Limit: 128 MB Description 一天,Besssie准备和FJ挑战奶牛跳棋游戏.这个游戏上在一个M*N(1<=M<=1,000,000;1<=N<=1,000,000)的棋盘上, 这个棋盘上在(x,y)(0<=x棋盘的左下角是(0,0)坐标,棋盘的右上角是坐标(M-1,N-1). Bessie每次都是第一个移动棋子,然后Bessie与

[最短路]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 deliver plenty of ice cold nutritiou