http://codeforces.com/contest/366/problem/D

遍历下界,然后用二分求上界,然后用dfs去判断是否可以。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 10000
using namespace std; int n,m;
int head[maxn];
bool vis[maxn];
int e;
int pl[maxn],pr[maxn];
int ans;
struct node
{
int u,v;
int l,r;
int next;
}p[maxn*]; void inti()
{
memset(vis,false,sizeof(vis));
memset(head,-,sizeof(head));
e=;
} void add(int u,int v,int l,int r)
{
p[e].u=u;
p[e].v=v;
p[e].l=l;
p[e].r=r;
p[e].next=head[u];
head[u]=e++;
} bool dfs(int u,int l,int r)
{
if(l>r) return false;
vis[u]=true;
if(u==n) return true;
for(int i=head[u]; i!=-; i=p[i].next)
{
int v=p[i].v,ll=p[i].l,rr=p[i].r;
if(!vis[v])
{
if(ll<=l&&rr>=r)
{
if(dfs(v,l,r)) return true;
}
}
}
return false;
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
inti();
int u,v,l,r;
int cnt=;
for(int i=; i<=m; i++)
{
scanf("%d%d%d%d",&u,&v,&l,&r);
add(u,v,l,r);
add(v,u,l,r);
pl[cnt]=l;
pr[cnt++]=r;
}
ans=-;
sort(pl,pl+cnt);
sort(pr,pr+cnt);
for(int i=; i<cnt; i++)
{
int l1=;
int r1=cnt;
int mid=(l1+r1)>>;
while(l1<r1)
{
memset(vis,false,sizeof(vis));
if(dfs(,pl[i],pr[mid])) l1=mid+;
else r1=mid; mid=(l1+r1)>>;
}
if(pl[i]<=pr[mid-])
{
ans=max(ans,pr[mid-]-pl[i]+);
}
}
if(ans==-) printf("Nice work, Dima!\n");
else printf("%d\n",ans);
}
return ;
}

cf D. Dima and Trap Graph的更多相关文章

  1. Codeforces 336D Dima and Trap Graph 并查集

    Dima and Trap Graph 枚举区间的左端点, 然后那些左端点比枚举的左端点小的都按右端点排序然后并查集去check #include<bits/stdc++.h> #defi ...

  2. Codefroces 366 D Dima and Trap Graph (最短路)

    Dima and Trap Graph 题意:Dima和Inna越来越喜欢对方,但是Dima的室友缺很没有热情出去玩,然后Dima就把他室友Seryozha骗进了陷阱里.现在Seryozha想要从陷阱 ...

  3. cf 366D D. Dima and Trap Graph (计算所有线段共同覆盖的某段区间)

    http://codeforces.com/problemset/problem/366/D 题意:给出n个点,m条边,a,b,ll,rr分别代表点a,点b相连,点a和点b的区间范围(ll,rr),然 ...

  4. CF 366E Dima and Magic Guitar(最远哈密顿距离)

    题目链接:http://codeforces.com/problemset/problem/366/E 题意:给出一个n*m的数字矩阵A,每个矩阵元素的范围[1,K].给出一个长度为s的数字串B,B的 ...

  5. cf D George and Interesting Graph

    题意:给你一个有趣图的定义:在这个图中有一个根,根与每个点都有边和回边,除了根之外,其他的点的出度和入度都为2,然后给你一个图让你经过几步操作可以使此图变为有趣图,操作为:删边或者加边. 思路:枚举根 ...

  6. cf E. Dima and Magic Guitar

    http://codeforces.com/contest/366/problem/E |x1-x2|+|y1-y2|有四种情况 1.-(x1-x2)+(y1-y2); 2.(x1-x2)-(y1-y ...

  7. cf C. Dima and Salad

    http://codeforces.com/contest/366/problem/C 转化为背包问题,可以将a[i]-b[i]*k看成重量,a[i]为价值: 因为a[i]-b[i]*k可以为负数,所 ...

  8. cf B. Dima and To-do List

    http://codeforces.com/contest/366/problem/B 从0到k枚举起点,然后i+k判断是不是i+k>=n如果是i=(i+k)%n;否则i=i+k; #inclu ...

  9. cf D. Dima and Hares

    http://codeforces.com/contest/358/problem/D 题意:ai代表相邻的两个野兔都没有吃食物情况下的快乐系数,bi代表的是在相邻的两个野兔中有一个吃到食物的快乐系数 ...

随机推荐

  1. Android客户端实现七牛云存储文件上传

    1.简单文件上传  上传模型如下. 1.1获得Token 不管是简单文件上传,还是分片上传.断点续传 都需要首先访问服务器,以获得上传凭证信息Token..用于测试时,可以用本地模拟Token信息(有 ...

  2. Java---设计模块(值对象)

    ★ 场景和问题 在Java开发时,需要来回交换大量的数据,比如要为方法传入参数,也要获取方法的返回值,该如何能更好的进行数据的交互? ★ 基本的编写步骤 ◎第1步:写一个类,实现可序列化(如果以后数据 ...

  3. 兼容ie6/ff/ch/op的div+css实现的圆角框

    <!DOCTYPE html> <html> <head> <title>青春不迷茫:寻梦时代的“蚁族”逆袭之旅- 职场管理专题-中国人力资源开发网-中 ...

  4. paip.输入法编程---增加码表类型

    paip.输入法编程---增加码表类型 作者Attilax ,  EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/attil ...

  5. S-Nim

    http://acm.hdu.edu.cn/showproblem.php?pid=1536 SG经典题,不多说 // File Name: hdu1536.cpp // Author: bo_jwo ...

  6. spring 学习2

    package com.asm; //...省略导入的相关类 public class MessageController implements Controller { public ModelAn ...

  7. css文本样式

    1. body{ color:aqua; /*可继承的颜色*/ text-align: center; /*文本对齐方式*/ } 2.缩进: index.html <!DOCTYPE html& ...

  8. 在Eclipse里设置格式化代码时不格式化注释

    在Eclipse里设置格式化代码时不格式化注释 今天格式化代码 发现直接format会把注释也一块格式化了,有时候会把好好的注释弄的很乱.甚为头疼. 查阅之后解决办法如下: Windows -> ...

  9. Jsp详解

    1Jsp基础 1.1 Jsp引入 Servlet的作用: 用java语言开发动态资源的技术!!! Jsp的作用:用java语言(+html语言)开发动态资源的技术!!! Jsp就是servlet!!! ...

  10. JS 中的引用

    首先有一个全局变量  JsonArry={"key":"value"}; 假设这个object为{"你好":"引用"} ...