【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的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- 《黑马程序猿》 cocos2d游戏引擎复习笔记一
/** ----------------------------游戏场景的搭建-------------------------------- 1首先创建一个surfaceview ,它能够在子线程中 ...
- luogu4218 [JSOI2008] 最小生成树计数
题目大意 求一个加权无向图的最小生成树的个数.1<=n<=100; 1<=m<=1000,具有相同权值的边不会超过10条. 题解 命题1 由构成最小生成树的边的边权从小到大排序 ...
- UESTC--1252--24点游戏(dfs)
24点游戏 Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu Submit Status ...
- 利用expect验证主机口令
##########mianmi.sh############ #!/usr/bin/expect set ip [lindex $argv ] set password [lindex $argv ...
- md5的用处
MD5保存摘要及指纹信息 md5的用处: 1.保存用户密码2.校验数据的完整性
- 手写DAO框架(一)-从“1”开始
背景: 很久(4年)之前写了一个DAO框架-zxdata(https://github.com/shuimutong/zxdata),这是我写的第一个框架.因为没有使用文档,我现在如果要用的话,得从头 ...
- thinkphp 上传多张图片
tp3.23 没有找到同时上传多张图片 手册有讲过:http://www.kancloud.cn/manual/thinkphp/1876 其实可以通过,多张图片多次上传来到达效果 hmlt: < ...
- Android第三方微博、无线传输、动画特效、商城应用等源码
Android精选源码 Android汽车助手源码 一个酷炫的Android特效源码 新浪微博的第三方客户端.UI遵循Material Design. Android实现旋转木马布局多种效果 Andr ...
- dotnetnuke7.x 弹出窗口的皮肤加载问题
皮肤文件夹中必须要有popUpSkin.ascx才会正常加载skin.css文件
- 微软CRM4.0 页面表单和腾讯QQ在线整合
现在通过QQ和客户联系.洽谈业务及沟通感情的场合越来越多,在微软CRM表单上整合QQ可以方便的显示客户QQ在线状态,点击图标即可和客户进行QQ聊天. 客户在线状态: 客户离线状态: 输入QQ号码后即时 ...