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

【题意】

【题解】

设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. phoenixframe自己主动化測试平台对div弹出框(如弹出的div登陆框)的处理

    package org.phoenix.cases; import java.util.LinkedList; import org.phoenix.action.WebElementActionPr ...

  2. java 页面传输中文乱码解决方式

    post 中文乱码解决方案 接受数据的时候设置 request.setCharacterEncoding("utf-8");//编码必须和页面编码一致 页面设置 <%@pag ...

  3. CentOS/ubuntu iscsi initior target

    http://docs.oracle.com/cd/E26926_01/html/E25884/fpjwy.html iscsiadm: initiator reported error (24 - ...

  4. ride关键字

    定义变量:set variable 打印 :log 列表:create list 字符转数字型:evaluate 随机数:evaluate random.randint 日志截图:先导入screens ...

  5. js中 if不判断解决方式

    $(function() { $("#number").blur(function() { var number = $('#number').val(); var num = $ ...

  6. python 8:list.sort(reverse=false)、sorted(list, reverse=false)(对列表进行不可恢复排序;对列表进行可恢复排序)

    bicycles = ['trek', 'cannondale', 'redline', 'specialized'] print(bicycles) print(sorted(bicycles)) ...

  7. 3d数学 7 矩阵

    7.1 矩阵-数学定义 在线性代数中, 矩阵就是以行和列形式组织的矩形数字块.矩阵是向量的数组. 7.1.1 矩阵的维度和记法 矩阵的维度被定义为它包含了多少行和多少列.一个\(r \times c\ ...

  8. 7.Flask-上传文件和访问上传的文件

     1.1.上传文件和访问上传的文件 upload_file_demo.py from flask import Flask,request,render_template import os from ...

  9. 水仙花数------"水仙花数 "是指一个三位数,其各位数字立方和等于该数本身。(for循环的嵌套)

    package com.zuoye.test;//打印出所有的 "水仙花数 ",所谓 "水仙花数 "是指一个三位数,//其各位数字立方和等于该数本身.//例如: ...

  10. JAVA可能问的几个面试题问题及问题的标准答案

    问题一:你希望工作环境是怎样的? 标准答案:我对环境没有苛求,我会努力适应环境的. 注:此问题是在测试你的求职心态,是以自己为中心还是以工作为中心. 问题二:你觉得自己有哪些缺点? 标准答案:说一些对 ...