cf D. Dima and Trap Graph
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的更多相关文章
- Codeforces 336D Dima and Trap Graph 并查集
Dima and Trap Graph 枚举区间的左端点, 然后那些左端点比枚举的左端点小的都按右端点排序然后并查集去check #include<bits/stdc++.h> #defi ...
- Codefroces 366 D Dima and Trap Graph (最短路)
Dima and Trap Graph 题意:Dima和Inna越来越喜欢对方,但是Dima的室友缺很没有热情出去玩,然后Dima就把他室友Seryozha骗进了陷阱里.现在Seryozha想要从陷阱 ...
- 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),然 ...
- CF 366E Dima and Magic Guitar(最远哈密顿距离)
题目链接:http://codeforces.com/problemset/problem/366/E 题意:给出一个n*m的数字矩阵A,每个矩阵元素的范围[1,K].给出一个长度为s的数字串B,B的 ...
- cf D George and Interesting Graph
题意:给你一个有趣图的定义:在这个图中有一个根,根与每个点都有边和回边,除了根之外,其他的点的出度和入度都为2,然后给你一个图让你经过几步操作可以使此图变为有趣图,操作为:删边或者加边. 思路:枚举根 ...
- 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 ...
- cf C. Dima and Salad
http://codeforces.com/contest/366/problem/C 转化为背包问题,可以将a[i]-b[i]*k看成重量,a[i]为价值: 因为a[i]-b[i]*k可以为负数,所 ...
- 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 ...
- cf D. Dima and Hares
http://codeforces.com/contest/358/problem/D 题意:ai代表相邻的两个野兔都没有吃食物情况下的快乐系数,bi代表的是在相邻的两个野兔中有一个吃到食物的快乐系数 ...
随机推荐
- Android 给TextView添加点击事件
首先设定TextView的clickable属性为true. 可以在布局文件中进行设定,比如: <TextView android:id="@+id/phone" andro ...
- mysql之事务
事务处理 begin 开始一个事物 commit 事务确认 rollback 事务回滚 end 事务结束 innodb下可以实现事务 开始执行事务时如果 ...
- gis论坛
http://bbs.csdn.net/forums/GIS/ http://forums.mysql.com/list.php?23 http://www.remotegis.net/ http:/ ...
- 命名实参和可选实参(C# 编程指南)
https://msdn.microsoft.com/zh-cn/library/dd264739.aspx CalculateBMI(weight: 123, height: 64); Calcul ...
- hdu&&poj搜索题题号
搜索 hdu1067 哈希 hdu1401 双向搜索 hdu1430 哈希 hdu1667 跌搜+启发式函数 hdu1685 启发式搜索 hdu1813 启发式搜索 hdu1885 状态压缩搜索 hd ...
- 程序设计实习MOOC / 继承和派生——编程作业 第五周程序填空题1
描述 写一个MyString 类,使得下面程序的输出结果是: 1. abcd-efgh-abcd- 2. abcd- 3. 4. abcd-efgh- 5. efgh- 6. c 7. abcd- 8 ...
- 再看C
1. clrscr(void) 清屏 clear screen;gotoxy(x,y); 移动光标至指定位置;
- 联系我们_你我想法_【有男度】UNANDU 100%进口 全球设计师品牌精汇 男装_男装搭配_时尚男装_品牌男装_男装搭配技巧_男装网站
联系我们_你我想法_[有男度]UNANDU 100%进口 全球设计师品牌精汇 男装_男装搭配_时尚男装_品牌男装_男装搭配技巧_男装网站 联系我们 2012-02-17 国内北京公司总部 邮编 ...
- ORCL_UNINSTALL_WIN10
1.开始->设置->控制面板->管理工具->服务 停止所有Oracle服务. 2.运行Universal Installer 3.选择卸载产品 4.只勾选Oracle Data ...
- linux下javaEE系统安装部署
最近公司在将服务器往阿里云上面迁移,所以需要重新在linux上面安装相关的软件以及部署项目,这里用到的linux版本为centos7.0,需要安装的软件有 jdk1.7.mysql5.6.mongo3 ...