【题目链接】:http://codeforces.com/problemset/problem/95/C

【题意】



给你n个点,m条边;

每个点有一辆出租车;

可以到达离这个点距离不超过u的点,且在这个距离范围里面,路费都是v;

问你从起点到终点的最小花费;

【题解】



重新建图;

每个点;

连一条边到这个点的出租车能够到达的点(从每个点求最短路);

然后边权都是v;

然后在从这个新建的图上从起点开始跑最短路;



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1100;
const LL oo = 1e15; int n,m,s,t,u,v,w;
LL dis[N];
vector <pii> G[2][N];
queue <int> dl;
bool inq[N]; void spfa(int s,int p){
dl.push(s);
inq[s] = true;
rep1(i,1,n) dis[i] = oo;
dis[s] = 0;
while (!dl.empty()){
int x = dl.front();
inq[x] = false;
dl.pop();
int len = G[p][x].size();
rep1(i,0,len-1){
pii temp = G[p][x][i];
int y = temp.fi;
LL w = temp.se;
if (dis[y]>dis[x]+w){
dis[y] = dis[x]+w;
if (!inq[y]){
inq[y] = true;
dl.push(y);
}
}
}
}
} int main(){
//Open();
Close();//scanf,puts,printf not use
//init??????
cin >> n >> m;
cin >> s >> t;
rep1(i,1,m){
cin >> u >> v >> w;
G[0][u].pb(mp(v,w));
G[0][v].pb(mp(u,w));
}
rep1(i,1,n){
cin >> u >> v;
spfa(i,0);
rep1(j,1,n)
if (j!=i && dis[j]<=u){
G[1][i].pb(mp(j,v));
}
}
spfa(s,1);
if (dis[t]>=oo)
cout <<-1<<endl;
else
cout <<dis[t]<<endl;
return 0;
}

【codeforces 95C】Volleyball的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. NTP同步底层实现

    RFC http://www.ietf.org/rfc/rfc5905.txt https://www.eecis.udel.edu/~mills/ntp/html/select.html https ...

  2. kafka内外网集群配置

    linux下配置使用以第一台为例(先配置好jdk环境)1.解压kafka:2.10-0.10.1.12.修改zookeeper.properties 新增配置:maxClientCnxns=0 tic ...

  3. JS 将有父子关系的数组转换成树形结构数据

    将类似如下数据转换成树形的数据 [{ id: 1, name: '1', }, { id: 2, name: '1-1', parentId: 1 }, { id: 3, name: '1-1-1', ...

  4. CSS布局总结(一)

    前言:今天是学校为期六周的实训第一天,实训课感觉很水,第一天讲的竟然是HTML...实训老师丢了一个静态页面给我们做.感觉很久没写过这种东西,突然觉得自己的基本功很渣.布局这方面感觉需要总结一下,然后 ...

  5. selenium chrome.options禁止加载图片和js

    #新建一个选项卡 from selenium import webdriver options = webdriver.ChromeOptions() #禁止加载图片 prefs = { 'profi ...

  6. Git:Git入门及基本命令

    Git的结构: Git和代码托管中心 局域网环境下: 1)GitLab服务器 外网环境下: 2)github 3)码云 代码托管中心的任务:维护远程库 本地库和远程库的交互 团队内部协作 跨团队协作 ...

  7. fetch 如何请求数据

    fetch 如何请求数据 在 传统Ajax 时代,进行 API 等网络请求都是通过XMLHttpRequest或者封装后的框架进行网络请求,然而配置和调用方式非常混乱,对于刚入门的新手并不友好 二 与 ...

  8. sql 语句中的 (+) 是什么意思?

    在select语句中(+)指的是外连接,是连接查询的一种方法.例:select t1.*,t2.* from dept t1,emp t2 where t1.deptno=t2.deptno(+);其 ...

  9. Mysql学习总结(31)——MySql使用建议,尽量避免这些问题

    做服务器端开发的同学们,相信对于mysql应该是十分熟悉,但是一旦真正出现问题,你是否能够快速的发现问题的起因,并且解决呢?一旦问题涉及到数据库层面,往往不是那么好解决的,通常来说,我们需要提前做应对 ...

  10. LIVE555研究之五:RTPServer(二)

    port是一样的. DynamicRTSPServer 继承关系: Medium是非常多类的基类.内部定义了指向环境类的引用和一个char类型媒体名称.并定义了依照媒体名称,查找相应媒体的成员函数lo ...