【codeforces 95C】Volleyball
【题目链接】: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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- [读书笔记] R语言实战 (五) 高级数据管理
1. 数值函数 1) 数学函数 2) 统计函数 3. 数据标准化 scale() 函数对矩阵或者数据框的指定列进行均值为0,标准化为1的标准化 mydata <- data.frame(c1=c ...
- java实现支付宝电脑支付(servlet版本)
前期准备: 蚂蚁金融开放平台 进行登录操作 进入我的开放平台 在上方找到沙箱,进入沙箱(网络编程虚拟执行环境). 这里的RSA2密钥设置下,我已经设置好了,所以便有了支付宝公钥(公钥是对外公开的,私钥 ...
- Mybatis之MySql批量insert后返回主键
需求:使用批量插入后,需要insert之后的每一条记录的ID 注意:Mybatis3.3.1的版本以后支持批量插入后返回主键ID 示例: domin.java: public class User { ...
- 【codeforces 235B】Let's Play Osu!
[题目链接]:http://codeforces.com/problemset/problem/235/B [题意] 让你玩一个游戏,游戏结果由一个长度为n的01字符组成; 这个结果的分数与连续的1的 ...
- Nutch2 WebPage写入数据库的过程分析
版本: Nutch 2.2.1 本文通过InjectJob来追踪webpage的定义.创建.传递.序列化.写入数据库的整个过程.从源码中摘录了重要的代码行,并标明其所在文件名.行号. 1. 定义 sc ...
- soapUI 5.1.2 下载以及破解
转:https://blog.csdn.net/weiqing723/article/details/78865734
- 鸟哥的Linux私房菜-----11、压缩指令与正则表示法
- [Tools] Create your own mobile emulator device by using Chrome dev tool
Using the New Device Emulation Interface The Device Emulation interface changed a bit with the newer ...
- c++变量的作用域、生存期和可见性
局部变量 范围:在一个函数内部定义的变量,作用范围仅仅限于本函数体内. 生存期:程序运行到本函数才会给局部变量分配内存单元.函数运行完成局部变量所占的存储单元就被释放 全局变量 在函数体外部定义的变量 ...
- ORA 12505 Listener does not currently know of SID given in connection descriptor
oracle数据库正常启动后.在本地能够正常訪问,可是远程使用sqldevelop却不能訪问.提示ORA 12505 Listener does not currently know of SID g ...