Cs Round#54 E Late Edges
题意:给定一个无向图,你从结点1开始走,每经过一条边需要1的时间,每条边都有一个开放时间,只有当目前所用的时间大于等于开放时间时,这条边才可以被经过。每一单位时间你都必须经过一条边,问最快什么时候可以到达N
一开始觉得当一条边未开放时,最优的策略便是在当前结点和上次经过的结点间徘徊,知道结点开放,于是最少的徘徊次数便是那条边的边权。后面发现奇偶性其实会影响答案。于是将dis分为奇偶跑pb_ds优化的dijkstra即可。
PS:比赛时竟然有人三分钟把这道题切了,再一次证明了我好菜233333
#include<bits/stdc++.h>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;
#define MAXN 10000+10
typedef long long LL;
const LL INF=;
struct edge{int v,next;LL w;}edge[MAXN*];
struct Ed{
int u,p;LL w;
Ed(){}
Ed(int u,int p,LL w):u(u),p(p),w(w){}
bool operator >(const Ed &a)const{return w>a.w;}
};
typedef __gnu_pbds::priority_queue<Ed,greater<Ed>,__gnu_pbds::thin_heap_tag>heap;
int n,m,head[MAXN],un[MAXN][];
LL dis[MAXN][];
heap::point_iterator it[MAXN][];
heap q;
void add(int u,int v,LL w){
static int tot=;
edge[++tot].v=v;
edge[tot].w=w;
edge[tot].next=head[u];
head[u]=tot;
}
LL val(LL x,LL y){
if(x>=y)return ;
return ((y-x)&)?(y-x+):y-x+;
}
void dijkstra(){
for(int i=;i<=n;i++)dis[i][]=dis[i][]=INF;
dis[][]=;
for(int i=;i<=n;i++){
it[i][]=q.push((Ed){i,,dis[i][]});
it[i][]=q.push((Ed){i,,dis[i][]});
}
q.push((Ed){,,});
while(!q.empty()){
int u=q.top().u,p=q.top().p;
q.pop();
if(un[u][p])continue;
un[u][p]=;
for(int i=head[u];i;i=edge[i].next){
int v=edge[i].v,w;
w=max(1LL,val(dis[u][p],edge[i].w));
LL tmp=dis[u][p]+w;
if(!un[v][tmp&]&&dis[u][p]+w<dis[v][tmp&]){
dis[v][tmp&]=tmp;
q.modify(it[v][tmp&],(Ed){v,tmp&,dis[v][tmp&]});
}
}
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
int u,v;LL w;
scanf("%d%d%lld",&u,&v,&w);
add(u,v,w);add(v,u,w);
}
dijkstra();
if(min(dis[n][],dis[n][])==INF)printf("-1\n");
else printf("%lld\n",min(dis[n][],dis[n][]));
return ;
}
Cs Round#54 E Late Edges的更多相关文章
- Cs Round#54 D Spanning Trees
题意:构造一张N个结点无重边.无自环的无向图.使得其最小生成树和最大生成树共享K条边. 样例一很具有启发性: 当K!=0时,我们可以先构造出一条链,链的长度为n-k的链,作为最小生成树的一部分,之后由 ...
- CSA Round #54 $\ $Voting
CSA Round #54 \(\ \)Voting 题目大意: 原题网址:戳我戳我! 一次歌唱比赛中,一位歌手刚刚结束表演,评委正在打分. 一共有 \(n\) 位评委,他们每人可以打 \(1\) 分 ...
- Codeforces Beta Round #54 (Div. 2)
Codeforces Beta Round #54 (Div. 2) http://codeforces.com/contest/58 A 找子序列 #include<bits/stdc++.h ...
- CS Round#53 C Histogram Partition
题意:给定一个数组A,以及一个初始值全为0的空数组B,每次可以对数组B的任意一个区间内的所有数+x,问至少几次操作能把B数组变成A数组 NOIP原题(积木大赛)升级版,话说CS怎么那么多跟NOIP原题 ...
- Educational Codeforces Round 54
这套题不难,但是场上数据水,导致有很多叉点 A. 因为是让求删掉一个后字典序最小,那么当a[i]>a[i+1]的时候,删掉a[i]一定最优!这个题有个叉点,当扫完一遍如果没有满足条件的,就删去最 ...
- Educational Codeforces Round 54 (Rated for Div. 2) ABCD
A. Minimizing the String time limit per test 1 second memory limit per test 256 megabytes Descriptio ...
- CH Round #54 - Streaming #5 (NOIP模拟赛Day1)解题报告
最近参加了很多CH上的比赛呢~Rating--了..题目各种跪烂.各种膜拜大神OTZZZ T1珠 描述 萌蛋有n颗珠子,每一颗珠子都写有一个数字.萌蛋把它们用线串成了环.我们称一个数字串是有趣的,当且 ...
- CH Round #54 - Streaming #5 (NOIP模拟赛Day1)
A.珠 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2354%20-%20Streaming%20%235%20(NOIP模拟赛Day1)/珠 题解:sb题, ...
- Cs Round#56 D Find Path Union
题意:有一棵如下的完全二叉树,求所有给定结点到根节点的路径的并有多少条边. 一开始联想到线段树,发现结点的排布很像线段树的标号.于是模仿线段树敲了一下,交上去发现3个点MLE了... 无心优化,跑去看 ...
随机推荐
- 快速配置vs2012+opencv
关于OpenCV+Windows+VS配置的文章网上有很多,多是类似 OpenCV中文网 上的安装方法. 不管什么方法,配置的步骤毫无疑问是: 1. 配置环境变量, 2. 配置VS. 在这个过程中,令 ...
- BabeLua常见问题
BabeLua常见问题 来源: http://blog.csdn.net/babestudio/article/details/27228865 怎样升级BabeLua? https://babelu ...
- Muduo阅读笔记---入门(一)
第一步:下载源码和文档 下载muduo项目的源码.<muduo-manual.pdf>文档,以及<Linux多线程服务端编程:使用muduo C++网络库.pdf>,这些是前期 ...
- Codeforces Round #383 (Div. 2)C. Arpa's loud Owf and Mehrdad's evil plan
C. Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 me ...
- Android 开发笔记___spinner__适配器基础_arrayadapter
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...
- Rem与Px的转换[转载]
原文:http://www.w3cplus.com/preprocessor/sass-px-to-rem-with-mixin-and-function.html rem是CSS3中新增加的一个单位 ...
- html5客户端本地存储之sessionStorage及storage事件
首先您可以看一下<JavaScript本地存储实践(html5的localStorage和ie的userData)>sessionStorage和上文中提到的localStorage非常相 ...
- HTTP协议相关知识点
主要参考 http://www.imooc.com/article/14397,来源:慕课网,作者种子_fe HTTP是超文本传输协议,主要特点有: 支持客户.服务器模式 简单快速:客户向服务器请求服 ...
- YII2调试 通过日志记录将变量保存到文件
$log = new \yii\log\FileTarget(); $content=var_export($menu,"true");//将数组或对象转换字符串格式 $con ...
- 关于Python在Linux、Mac和Windows上的安装方法总结
一.Linux下安装python 1.python源码安装包下载地址: https://www.python.org/downloads/source/ 2.下载完tar.xz压缩包以后, ...