【Codeforces 229B】Planets
【链接】 我是链接,点我呀:)
【题意】
【题解】
设dis[i]表示到达i号传送器的最早时刻.
显然,虽然有那么多的出发时刻的限制,但我们还是越早到越好的.
因为你到得越早,出发的时间肯定不会比到达的时刻晚的差.
所以,就是一个最短路的问题啦.
因为数据范围比较大.
所以得用dijkstra+优先队列的优化.
在出去的时候,只要枚举一遍到达这个点的所有时刻,就能知道它啥时候出发了.
因为∑ki
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
using namespace std;
const int N = 1e5;
int n,m;
vector<pair<int,int> > g[N+10];
vector<int> a[N+10];
int dis[N+10];
priority_queue<pair<LL,int>,vector<pair<LL,int> >,greater<pair<LL,int> > > pq;
int main()
{
scanf("%d%d",&n,&m);
rep1(i,1,m){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
g[x].push_back(make_pair(y,z));
g[y].push_back(make_pair(x,z));
}
for (int i = 1;i <= n;i++){
int cnt;
scanf("%d",&cnt);
rep1(j,0,cnt-1){
int x;
scanf("%d",&x);
a[i].push_back(x);
}
}
rep1(i,1,n) dis[i] = -1;
dis[1] = 0;
pq.push(make_pair(0,1));
while (!pq.empty()){
pair<LL,int> temp = pq.top();pq.pop();
int x = temp.second;LL disx = temp.first;
if (dis[x]<disx) continue;
rep1(i,0,(int)a[x].size()-1)
if (a[x][i]==disx)
disx++;
for (pair<int,int> temp1:g[x]){
int y = temp1.first,cost = temp1.second;
if (dis[y]==-1 || dis[y]>cost+disx){
dis[y] = cost+disx;
pq.push(make_pair(dis[y],y));
}
}
}
cout<<dis[n]<<endl;
return 0;
}
【Codeforces 229B】Planets的更多相关文章
- 【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的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- Mahout算法调用展示平台2.1
软件版本号: windows7: Tomcat7.JDK7.Spring4.0.2.Struts2.3.Hibernate4.3.myeclipse10.0.easyui:Linux(centos6. ...
- machine learning in coding(python):使用贪心搜索【进行特征选择】
print "Performing greedy feature selection..." score_hist = [] N = 10 good_features = set( ...
- 协同过滤算法中皮尔逊相关系数的计算 C++
template <class T1, class T2>double Pearson(std::vector<T1> &inst1, std::vector<T ...
- 联想Thinkpad L460安装Win7 64位
单位发了L460,自带的系统为win10,但是涉及到很多工作以及客户都是在win7环境下,所以必须安装win7的系统,经过一番折腾,终于装好了. 主要顺序如下: 1,制作WINPE启动盘,如大白菜,老 ...
- PCB SQL MS 将多行有序数据转为一行数据(一列转一行)
一.原数据:多行有序 SELECT CC.techname FROM PPEflow BB LEFT JOIN pubgyxxb CC ON BB.techno = CC.techno ORDER B ...
- 昂贵的聘礼(Dijkstra)
http://poj.org/problem?id=1062 每个物品看成一个节点,酋长的允诺也看作一个物品, 如果一个物品加上金币可以交换另一个物品,则这两个节点之间有边,权值为金币数,求第一个节点 ...
- bzoj 3172 单词
3172: [Tjoi2013]单词 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 3937 Solved: 1912[Submit][Status ...
- Windows7下caffe-ssd-microsoft下编译
整个编译可谓漫长 编译了两天 网上教程也很多 但是也很杂 遇到各种错误 总归是编完了 1.下载Windows版本的Caffe-SSD源码 下载链接:https://github.com/conner9 ...
- SnackDown Online Qualifier 2017
好久没做题了,然后就想着随便做一个.无奈cf都是晚上,然后就看见这个,随便做做. 资格赛,只要做出来1题就行了,4天的时间. 1. 水题 #include <iostream> #incl ...
- 【转】Postman接口测试之POST、GET请求方法
转自竹小冉: https://www.cnblogs.com/zhuxr/p/9009708.html 一.基础知识 1.HTTP的五种请求方法:GET, POST ,HEAD,OPTIONS, PU ...