【题目链接】: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. create raid5

    # umout 所有数据disk for i in {1..11};do umount /disk$i;done # 修改/etc/fstab,注释掉 /dev/sd[b-l] vim /etc/fs ...

  2. HTML特殊符号对照表、常用的字符实体

    来源:http://tool.xker.com/htmlchar.php 最常用的字符实体 显示结果 描述 实体名称 实体编号   空格     < 小于号 < < > 大于号 ...

  3. STM32CubeMx的使用分享

    1. 新建立工程(以F103ZET6为例) 2. 配置引脚(以PA0为例)   3. 配置外设(以串口为例) 4. 配置时钟 5. 外设.GPIO.中断初始化 6. 生成工程 7. 添加自己的代码 8 ...

  4. HTML5 基础测试题

          HTML5 基础测试题 1.HTML5 之前的 HTML 版本是什么?() A.HTML 4.01 B.HTML 4 C.HTML 4.1 D.HTML 4.9 2.HTML5 的正确 d ...

  5. .get(),eq()的区别

    .get(),eq()的区别 eq:返回是一个jquery对象作用是将匹配的元素集合缩减为一个元素.这个元素在匹配元素集合中的位置变为0,而集合长度变成1. get:是一个html对象数组作用是取得其 ...

  6. Spring+mybatis+struts框架整合的配置具体解释

    学了非常久的spring+mybatis+struts.一直都是单个的用他们,或者是两两组合用过,今天总算整合到一起了,配置起来有点麻烦.可是配置完一次之后.就轻松多了,那么框架整合配置具体解释例如以 ...

  7. POJ 3664 Election Time 题解

    这道题网上非常多人都会说easy,水题之类的话,只是我看了下说这种话的人的程序,能够说他们的程序都不及格! 为什么呢?由于他们的程序都是使用简单的二次排序水过(大概你能搜索到的多是这种程序).那样自然 ...

  8. HDU 1285--确定比赛名次【拓扑排序 &amp;&amp; 邻接表实现】

    确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  9. oracle实现自增id

    --oracle实现自增id --创建一张T_StudentInfo表 create table T_StudentInfo ( "id" integer not null pri ...

  10. 4.git "Could not read from remote repository.Please make sure you have the correct access rights."解决方案

    转自:https://zhiku8.com/git-could-not-read-from-remote-repository.html 我们在使用git clone 或其他命令的时候,有时候会遇到这 ...