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. 【HDOJ】1011 Starship Troopers

    第一道树形DP.很容易理解. #include <cstdio> #include <cstring> #include <cstdlib> #define MAX ...

  2. BZOJ3538: [Usaco2014 Open]Dueling GPS

    3538: [Usaco2014 Open]Dueling GPS Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 59  Solved: 36[Subm ...

  3. 【转】s3c2440 按键驱动 — 字符设备

    原文网址:http://www.xuebuyuan.com/632893.html 主机:VM - redhat 9.0 开发板:FL2440,linux-2.6.12 arm-linux-gcc:3 ...

  4. iOS项目更新之升级Xcode7 & iOS9

    金田 前言      Apple 的WWDC所发布内容在给大家带来惊喜之际,给各位iOS开发的同仁却也带来了不同程度的麻烦.首先不讲新功能,就单指原来老版本的项目升级.代码升级,就是一堆问题,而且是不 ...

  5. ViewPager的使用方法和实现过程

    布局文件里添加viewPager布局 <android.support.v4.view.ViewPager android:id="@+id/search_viewpager" ...

  6. hdu 1331 Function Run Fun

    Problem Description We all love recursion! Don't we? Consider a three-parameter recursive function w ...

  7. 模型-视图-控制器 (MVC)

    在MVC中 ,模型代表数据和业务规则, 视图包含了用户界面元素,例如文本,表单等 控制器则管理模型和视图中的通信

  8. delphi算法

    /  求余 mod 取模 var a1,a2,a3 : Integer; b1,b2,b3 : Integer; c1,c2 : Integer;begin a1 := 987; //ShowMess ...

  9. 〖转〗request.getparameter()和request.getAttribute()的区别

    getAttribute表示从request范围取得设置的属性,必须要先setAttribute设置属性,才能通过getAttribute来取得,设置与取得的为Object对象类型 getParame ...

  10. VMware Virtual Machine安装报错解决1

    安装完VMware virtual machine 后,再进行 "create a new virtual machine"最后点击"Finish"时,报如下错 ...