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

news/2024/7/24 11:44:52

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

 

转载于:https://www.cnblogs.com/JSZX11556/p/4575799.html


http://www.niftyadmin.cn/n/1811235.html

相关文章

活着的滋味!差距!让人心酸!

本文网址:http://bbs5.news.163.com/board/rep.jsp?btalk&i246484 复制 一排黑锅灶让人心酸   每来一名学生&#xff0c;队员们就赶忙帮他们卸下肩膀上的扁担&#xff0c;帮他们拿被褥和大米。实践队员在食堂外的走廊上看到了一排黑糊糊的碎砖头&#xff0c;如果不是…

杨森翔的书法:书法

转载于:https://www.cnblogs.com/ysx4221/p/4831923.html

重中之重:委托与事件

相关文章链接 编程之基础&#xff1a;数据类型&#xff08;一&#xff09; 编程之基础&#xff1a;数据类型&#xff08;二&#xff09; 高屋建瓴&#xff1a;梳理编程约定 动力之源&#xff1a;代码中的泵 难免的尴尬&#xff1a;代码依赖 可复用代码&#xff1a;组件的来龙去…

一张神奇图片→测试你的心理承受力

据心理医生说&#xff0c; 图片 与心理承受力有关&#xff0c;你的心理承受力越强&#xff0c; 图片 转动越慢。    美国曾经以此作为犯罪嫌疑人的心理测试&#xff0c;他看到的 图片 是高速旋转的&#xff0c;而大部分的老人和儿童看这幅 图片 是静止的。 大家看…

python在图片上写汉字,并竖向排列在图片上

当我们用opencv在图片上写汉字,使用的是putText,会遇到只能写英文,写中文的话,会遇到报错。 这个时候我们只需要转成PIL格式,对其输入中文,再转会opencv格式就好 代码如下: import cv2 import os import numpy as np from PIL import ImageFont, ImageDraw, Imagefps…

python读取歌词文本,并显示在图片上,制作视频

首先是歌词的准备,我们放到txt文本中即可 写给代码将歌词读入 txt = with open("一曲相思.txt", "r",encoding=utf-8) as f: # 打开文件data = f.readlines() # 读取文件print(data) for i in range(len(data)):txt += data[i] print(txt) 显示结果…

XSS前端防火墙

前一段时间&#xff0c;在EtherDream大神的博客里看到关于XSS防火墙的一系列文章&#xff0c;觉得很有意思。刚好科创要做一个防火墙&#xff0c;就把XSS前端防火墙作为一个创新点&#xff0c;着手去实现了。 在实现过程中&#xff0c;由于各种原因&#xff0c;比如说JavaScrip…

自定义 MVC 框架思想

目录 一、MVC设计模式 1. 什么是MVC 2. 三层架构与MVC的区别 二、自定义MVC框架 1. 为什么要学习自定义MVC框架 2. 自定义MVC的工作原理 3. 自定义MVC框架的优势 三、自定义MVC实例流程 1. mvc三层架构的弊端 2. 自定义MVC的工作流程 2.1 子控制器&#xff08;…