【链接】 我是链接,点我呀:)

【题意】

【题解】

设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的更多相关文章

  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. luogu1726 上白泽慧音

    题目大意 求一个有向图含节点数最多且结点编号从小到大排列字典序最小的强连通分量. 注意事项 HDU1269那道题题面.数据太弱,在这道题上把我害惨了... Dfs点u时,如果与u相连的一个点v有Dfs ...

  2. SpringCloud 之 Fegin —— 发送GET、POST请求以及文件上传

    由于项目需要调用其他微服务的数据,首先想到的就是写一个http网络请求的工具类,但是想到在之前看springCloud的时候里面有这个Fegin可以实现,就顺便实践一下,虽然过程有点坎坷,好在都顺利解 ...

  3. 关于函数提升在if语句中的表现

    函数声明创建的函数在现代浏览器,在if语句中函数的声明不会提升,但是在老的IE版本中,if语句中的函数声明会提升 函数表达式在不同浏览器中函数声明都不会被提升,解决了不同浏览器的兼容性问题 关于函数提 ...

  4. 强迫症!一行代码拿到url特定query的值

    简单的说一下背景,看到小伙伴给我发的项目中有一段获取当前url特定query值的代码,本着能写1行代码就不写5行代码的原则,我把这个获取方法给改了一下 之前的代码如下: const queryArr ...

  5. 【poj1995】快速幂

    题目大意 求a^b %p 1≤a,b,p≤10^9 思路 时间O(10^9)一定会爆T,采用数学方法+位运算,得到O(log b)的快速幂算法 代码 #include<cstdio> #i ...

  6. Spring Boot (5) Spring Boot配置详解

    application.properties application.properties是spring boot默认的配置文件,spring boot默认会在以下两个路径搜索并加载这个文件 src\ ...

  7. android.system.ErrnoException: open failed: ENOENT (No such file or directory) 07-19 20:27:45.011 66

    在操作安卓版本23+的文件读取时,不仅要在maniests中声明,还要在代码中动态声明: ; private static String[] PERMISSIONS_STORAGE = { Manif ...

  8. C# Socket通讯 本机多网卡,指定网卡通讯

    IPAddress ip = IPAddress.Parse("192.168.0.188"); IPAddress IPLocal = IPAddress.Parse(" ...

  9. VHDL之concurrent之operators

    Using operators Operators can be used to implement any combinational circuit. However, as will becom ...

  10. SQL Server之存储过程

    存储过程的概念 存储过程Procedure是一组为了完成特定功能的SQL语句集合,经编译后存储在数据库中,用户通过指定存储过程的名称并给出参数来执行. 存储过程中可以包含逻辑控制语句和数据操纵语句,它 ...