题目链接:

https://jzoj.net/senior/#main/show/5177

题目:

题解:

首先选出的泡泡怪一定是连续的一段 L,R

然后 L 一定属于虫洞左边界中的某一个 R 也同样是这样的

这样就可以枚举 L 和 R,$O(N)$判断是否可行(显然不可能重复经过某个点),总复杂度 $O(NM^2)$

我们看到 R<=1e6 选择二分 R 而不是枚举,这样就可以了

#include<algorithm>
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std; const int N=1e3+;
const int M=3e3+;
const int inf=1e6;
int n,m,tot;
int head[N],L[M],vis[N];
struct EDGE{
int to,nxt,l,r;
}edge[M<<];
inline int read(){
char ch=getchar();int s=,f=;
while (ch<''||ch>'') {if (ch=='-') f=-;ch=getchar();}
while (ch>=''&&ch<='') {s=(s<<)+(s<<)+ch-'';ch=getchar();}
return s*f;
}
void link(int u,int v,int l,int r){
edge[++tot]=(EDGE){v,head[u],l,r};
head[u]=tot;
}
bool dfs(int x,int l,int r)
{
if (x==n) return ;
if (vis[x]) return ;
vis[x]=;
for (int i=head[x];i;i=edge[i].nxt)
{
if (edge[i].l<=l&&edge[i].r>=r)
{
if (dfs(edge[i].to,l,r)) return ;
}
}
return ;
}
bool check(int l,int r)
{
memset(vis,,sizeof(vis));
if (dfs(,l,r)) return ;
return ;
}
int main()
{
n=read();m=read();
for (int i=,u,v,l,r;i<=m;i++){
u=read();v=read();l=read();r=read();
link(u,v,l,r);link(v,u,l,r);
L[i]=l;
}
sort(L+,L++m);
int ans=,al,ar;
for (int i=m;i;i--){
int l=L[i],r=inf;
while (l+<r)
{
int mid=l+r>>;
if (check(L[i],mid))
{
if (mid-L[i]+>=ans)
{
ans=mid-L[i]+;
al=L[i];ar=mid;
}
l=mid;
}
else r=mid;
}
}
printf("%d\n",ans);
for (int i=al;i<=ar;i++) printf("%d ",i);
return ;
}

[jzoj 5177] [NOIP2017提高组模拟6.28] TRAVEL 解题报告 (二分)的更多相关文章

  1. [jzoj 5178] [NOIP2017提高组模拟6.28] So many prefix? 解题报告(KMP+DP)

    题目链接: https://jzoj.net/senior/#main/show/5178 题目: 题解: 我们定义$f[pos]$表示以位置pos为后缀的字符串对答案的贡献,答案就是$\sum_{i ...

  2. [JZOJ 5852] [NOIP2018提高组模拟9.6] 相交 解题报告 (倍增+LCA)

    题目链接: http://172.16.0.132/senior/#main/show/5852 题目: 题目大意: 多组询问,每次询问树上两条链是否相交 题解: 两条链相交并且仅当某一条链的两个端点 ...

  3. [JZOJ5178]【NOIP2017提高组模拟6.28】So many prefix?

    Description

  4. nowcoder(牛客网)提高组模拟赛第一场 解题报告

    T1 中位数(二分) 这个题是一个二分(听说是上周atcoder beginner contest的D题???) 我们可以开一个数组b存a,sort然后二分b进行check(从后往前直接遍历check ...

  5. JZOJ 5184. 【NOIP2017提高组模拟6.29】Gift

    5184. [NOIP2017提高组模拟6.29]Gift (Standard IO) Time Limits: 1000 ms  Memory Limits: 262144 KB  Detailed ...

  6. JZOJ 5196. 【NOIP2017提高组模拟7.3】B

    5196. [NOIP2017提高组模拟7.3]B Time Limits: 1000 ms  Memory Limits: 262144 KB  Detailed Limits   Goto Pro ...

  7. JZOJ 5197. 【NOIP2017提高组模拟7.3】C

    5197. [NOIP2017提高组模拟7.3]C Time Limits: 1000 ms  Memory Limits: 262144 KB  Detailed Limits   Goto Pro ...

  8. JZOJ 5195. 【NOIP2017提高组模拟7.3】A

    5195. [NOIP2017提高组模拟7.3]A Time Limits: 1000 ms  Memory Limits: 262144 KB  Detailed Limits   Goto Pro ...

  9. JZOJ 5185. 【NOIP2017提高组模拟6.30】tty's sequence

    5185. [NOIP2017提高组模拟6.30]tty's sequence (Standard IO) Time Limits: 1000 ms  Memory Limits: 262144 KB ...

随机推荐

  1. 智课雅思词汇---十三、前缀ab-是什么意思

    智课雅思词汇---十三.前缀ab-是什么意思 一.总结 一句话总结:分离,脱离;相反;加强意义 前缀:ab- [词根含义]:分离,脱离;相反;加强意义 [词根来源]:来源于拉丁语前缀ab-. [同源单 ...

  2. 利用Spring Hibernate注解packagesToScan的简化自动扫描方式

    转自:https://blog.csdn.net/wzygis/article/details/28256045

  3. Redis学习笔记(十二) 高级命令:服务器管理命令

    原文链接:http://doc.redisfans.com/server/index.html save 执行一个同步操作,将redis实例的所有数据以rdb的形式保存到硬盘,一般来说,生产环境很少执 ...

  4. C语言“%”运算符

    C语言中运算符“%”是取余运算符,而非取模运算符.(运算符“%”在C/C++, JAVA中,为取余运算,而在Python中为取模运算) 对于一个C语言取余表达式a % b,设其值为result,有如下 ...

  5. Android 多线程下载 显示进度 速度

    功能要求:从网络下载一APK应用,显示下载速度.进度,并安装应用. 运行效果图: 工程结构图: 很简单,就一个activity,一个更新UI的线程,一个下载线程加个文件处理类 主要代码: /** *多 ...

  6. What is the difference between arguments and parameters?

    What is the difference between arguments and parameters? Parameters are defined by the names that ap ...

  7. CREATE TABLE 语句后的 ON [PRIMARY] 起什么作用

    CREATE   TABLE   [dbo].[table1]   ( [gh]   [char]   (10)   COLLATE   Chinese_PRC_CI_AS   NOT   NULL ...

  8. learn cmake

    cmake简介 在cmake出现之前,在linuxiax下,大型软件系统一般使用make来控制编译过程,而在Windows下可能是用vs下一个project来构建.一个复杂的系统本身依赖关系就很麻烦, ...

  9. C++ should define all local variable outside the loop?

    see the following two examples, the conclusion is that we should define variable in the loop if it c ...

  10. MySQL查询结果保存到本地

    #!/bin/bash mysql -h<公网IP> -P<端口号> -u<用户名> -p<密码> -D<指定数据库> >/Users ...