题意翻译

给出一个图,双向边,边上有权值代表路的距离,然后每个点上有两个值,t,c,t代表能从这个点最远沿边走t,且不能在半路下来,花费是c 现在告诉你起点终点,问最少的花费 点个数1000,边个数1000,边权1e9

By @partychicken

题目描述

Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has n n n junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads can have different lengths.

Initially each junction has exactly one taxi standing there. The taxi driver from the i i i -th junction agrees to drive Petya (perhaps through several intermediate junctions) to some other junction if the travel distance is not more than ti t_{i} ti​ meters. Also, the cost of the ride doesn't depend on the distance and is equal to ci c_{i} ci​ bourles. Taxis can't stop in the middle of a road. Each taxi can be used no more than once. Petya can catch taxi only in the junction, where it stands initially.

At the moment Petya is located on the junction x x x and the volleyball stadium is on the junction y y y . Determine the minimum amount of money Petya will need to drive to the stadium.

输入输出格式

输入格式:

The first line contains two integers n n n and m m m ( 1<=n<=1000,0<=m<=1000) 1<=n<=1000,0<=m<=1000) 1<=n<=1000,0<=m<=1000) . They are the number of junctions and roads in the city correspondingly. The junctions are numbered from 1 1 1 to n n n , inclusive. The next line contains two integers x x x and y y y ( 1<=x,y<=n 1<=x,y<=n 1<=x,y<=n ). They are the numbers of the initial and final junctions correspondingly. Next m m m lines contain the roads' description. Each road is described by a group of three integers ui u_{i} ui​ , vi v_{i} vi​ , wi w_{i} wi​ ( 1<=ui,vi<=n,1<=wi<=109 1<=u_{i},v_{i}<=n,1<=w_{i}<=10^{9} 1<=ui​,vi​<=n,1<=wi​<=109 ) — they are the numbers of the junctions connected by the road and the length of the road, correspondingly. The next n n n lines contain n n n pairs of integers ti t_{i} ti​ and ci c_{i} ci​ ( 1<=ti,ci<=109 1<=t_{i},c_{i}<=10^{9} 1<=ti​,ci​<=109 ), which describe the taxi driver that waits at the i i i
-th junction — the maximum distance he can drive and the drive's cost.
The road can't connect the junction with itself, but between a pair of
junctions there can be more than one road. All consecutive numbers in
each line are separated by exactly one space character.

输出格式:

If taxis can't drive Petya to the destination point, print "-1" (without the quotes). Otherwise, print the drive's minimum cost.

Please do not use the %lld specificator to read or write 64-bit
integers in С++. It is preferred to use cin, cout streams or the %I64d
specificator.

输入输出样例

输入样例#1:

4 4
1 3
1 2 3
1 4 1
2 4 1
2 3 5
2 7
7 2
1 2
7 7
输出样例#1:

9

说明

An optimal way — ride from the junction 1 to 2 (via junction 4), then from 2 to 3. It costs 7+2=9 bourles.

Solution:

  本题水。

  点数很小,先从每个点暴力最短路处理出该点的t范围内能到的点,并且建一张新图,然后只要在新图上再跑一遍最短路就好了。

代码:

/*Code by 520 -- 8.21*/
#include<bits/stdc++.h>
#define il inline
#define ll long long
#define RE register
#define For(i,a,b) for(RE int (i)=(a);(i)<=(b);(i)++)
#define Bor(i,a,b) for(RE int (i)=(b);(i)>=(a);(i)--)
using namespace std;
const int N=;
int n,m,s,t,a[N],b[N];
int to[N],net[N],w[N],h[N],cnt;
int To[N],Net[N],W[N],H[N],Cnt;
ll dis[N];
bool vis[N];
struct node{
int u;
ll d;
bool operator<(const node &a)const{return d>a.d;}
}; int gi(){
int a=;char x=getchar();
while(x<''||x>'')x=getchar();
while(x>=''&&x<='')a=(a<<)+(a<<)+(x^),x=getchar();
return a;
} il void add(int u,int v,int c){to[++cnt]=v,net[cnt]=h[u],w[cnt]=c,h[u]=cnt;} il void Add(int u,int v,int c){To[++cnt]=v,Net[cnt]=H[u],W[cnt]=c,H[u]=cnt;} queue<int>q;
il void spfa(int x){
For(i,,n) dis[i]=;
q.push(x),dis[x]=;
while(!q.empty()){
int u=q.front();q.pop();vis[u]=;
for(RE int i=h[u];i;i=net[i])
if(dis[to[i]]>dis[u]+w[i]){
dis[to[i]]=dis[u]+w[i];
if(!vis[to[i]])q.push(to[i]),vis[to[i]]=;
}
}
For(i,,n) if(i!=x&&dis[i]<=a[x]) Add(x,i,b[x]);
} priority_queue<node>Q;
il void dij(){
For(i,,n) dis[i]=;
dis[s]=,Q.push(node({s,}));
while(!Q.empty()){
node x=Q.top();Q.pop();
if(!vis[x.u]){
vis[x.u]=;
for(RE int i=H[x.u];i;i=Net[i])
if(dis[To[i]]>dis[x.u]+W[i]){
dis[To[i]]=dis[x.u]+W[i];
if(!vis[To[i]]) Q.push(node({To[i],dis[To[i]]}));
}
}
}
} il void init(){
n=gi(),m=gi(),s=gi(),t=gi();
int u,v,c;
For(i,,m) u=gi(),v=gi(),c=gi(),add(u,v,c),add(v,u,c);
For(i,,n) a[i]=gi(),b[i]=gi();
cnt=;
For(i,,n) spfa(i);
dij();
cout<<(dis[t]==?-:dis[t]);
} int main(){
init();
return ;
}

CF95C Volleyball的更多相关文章

  1. CF 96 D. Volleyball

    D. Volleyball http://codeforces.com/contest/96/problem/D 题意: n个路口,m条双向路,每条长度为w.每个路口有一个出租车司机,最多可以乘坐这辆 ...

  2. Codeforces 96D Volleyball(最短路径)

    Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't b ...

  3. Codeforces 95C Volleyball(最短路)

    题目链接:http://codeforces.com/problemset/problem/95/C C. Volleyball time limit per test 2 seconds memor ...

  4. Codeforces Beta Round #77 (Div. 1 Only) C. Volleyball (最短路)

    题目链接:http://codeforces.com/contest/95/problem/C 思路:首先dijkstra预处理出每个顶点到其他顶点的最短距离,然后如果该出租车到某个顶点的距离小于等于 ...

  5. *[hackerrank]Volleyball Match

    https://www.hackerrank.com/contests/w1/challenges/volleyball-match 此题不错,首先可以看出是DP,S(x, y)= S(x - 1, ...

  6. CF - 96D - Volleyball

    题意:一个无向图,有n个点,m条边,每条边有距离w,每个点有两个属性(1.从这点出发能到的最远距离,2.从这点出发的费用(不论走多远都一样)),一个人要从点x到点y,问最小费用是多少. 题目链接:ht ...

  7. 【日常训练】Volleyball(CodeForces-96D)

    题意与分析 这题也是傻逼题,可是我当时打比赛的时候板子出问题了- -|||,怎么调也调不过. 不过思路是很清晰的:先做n次dijkstra然后重新建图,建完了以后根据新的单向图再跑一次dijkstra ...

  8. 【codeforces 95C】Volleyball

    [题目链接]:http://codeforces.com/problemset/problem/95/C [题意] 给你n个点,m条边; 每个点有一辆出租车; 可以到达离这个点距离不超过u的点,且在这 ...

  9. mongo学习笔记(一):增删改查

    安装:我是按这篇来弄的 一.Insert 1.db.person.insert({"name":"jack","age":20}) 2.va ...

随机推荐

  1. ArcGIS API for JavaScript 4.2学习笔记[20] 使用缓冲区结合Query对象进行地震点查询【重温异步操作思想】

    这个例子相当复杂.我先简单说说这个例子是干啥的. 在UI上,提供了一个下拉框.两个滑动杆,以确定三个参数,使用这三个参数进行空间查询.这个例子就颇带空间查询的意思了. 第一个参数是油井类型,第二个参数 ...

  2. 解决注册并发问题并提高QPS

    前言:前面在本地的windows通过apache的ab工具测试了600并发下“查询指定手机是否存在再提交数据”的注册功能会出现重复提交的情况,并且在注册完成时还需要对邀请人进行奖励,记录邀请记录,对该 ...

  3. c++模板特化偏特化

    模板为什么要特化,因为编译器认为,对于特定的类型,如果你对某一功能有更好地实现,那么就该听你的. 模板分为类模板与函数模板,特化分为全特化与偏特化.全特化就是限定死模板实现的具体类型,偏特化就是模板如 ...

  4. 一个「学渣」从零开始的Web前端自学之路

    从 13 年专科毕业开始,一路跌跌撞撞走了很多弯路,做过餐厅服务员,进过工厂干过流水线,做过客服,干过电话销售可以说经历相当的“丰富”. 最后的机缘巧合下,走上了前端开发之路,作为一个非计算机专业且低 ...

  5. Oracle——DQL、DML、DDL、DCL

    1.DQL:数据查询语言 基本结构:由select.from.where组成 子句组成的查询块:    SELECT <字段名表>    FROM <表或视图名>    WHE ...

  6. Linux学习历程——Centos 7 touch命令

    一.命令介绍 touch 命令用于创建空白文件,以及设置文件的时间. ----------------------------------------------------------------- ...

  7. chrome打开收藏夹的网站在新的标签页

    chrome浏览器在新的标签页打开收藏夹的网址,现在设置不了,而且右键,在新标签页中打开有点烦..下面说说直接打开的方式. 方法1: 鼠标滚轮,直接点击收藏夹的网址,即可 方法2: ctrl + 鼠标 ...

  8. 一道C++、MFC上机面试题

    题目:写一个基于MFC对话框的程序,界面输入整型a和b,点击计算,开启线程计算a+b,并把结果返回给对话框.(1)不能用结构体和类(2)用到自定义消息(3)鼠标移到[计算]按钮上变为收尸图标.参考界面 ...

  9. hadoop 分析

    Hadoop源代码分析(一) Google的核心竞争技术是它的计算平台.Google的大牛们用了下面5篇文章,介绍了它们的计算设施. GoogleCluster:http://research.goo ...

  10. Spring-扫描注解原理,注解自动扫描原理分析

    注解自动扫描原理分析 在spring的配置文件中加入如下代码,spring便开启了自动扫描,那么它的底层到底是如何实现的呢? <context:component-scan base-packa ...