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代表的是在相邻的两个野兔中有一个吃到食物的快乐系数 ...
随机推荐
- C++中的基类和派生类
转载自:http://www.cnblogs.com/sujz/archive/2011/05/12/2044365.html 派生类的继承方式总结: 继承方式 说明 public 基类的public ...
- mysql导入数据大小设置方法
MySQL导入数据库文件最大限制2048KB和phpmyadmin导入数据最大限制2048KB的解决方法 解决办法: 1.打开php.ini.找到 upload_max_filesize . memo ...
- 关于Spring配置 (Cannot find class [org.apache.commons.dbcp.BasicDataSource] 问题)
myeclipse抛出异常 org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find /webapps/t ...
- linux下解压压缩rar文件
http://download.csdn.net/detail/hnust_xiehonghao/6679893 下载地址 1. 下载软件 以rarlinux-3.8.0 for linux为例, ...
- lesson6:java线程中断
正常的情况下,业务系统都不会去中断它的线程,但是由于一些特殊情况的发生,线程已经不能正常结束了,并且此类线程已经影响到业务系统提供服务的能力,如果系统设计的健壮,便会通过监控线程去主动的中断此类线程. ...
- JavaScript新手学习笔记3——三种排序方式(冒泡排序、插入排序、快速排序)
每种编程语言学到数组的时候,都会讲到排序算法,当时学C语言的时候,卡在排序算法.今天来总结一下javascript中如何实现三种排序算法. 1.冒泡排序(默认升序排列哦) 原理: 冒泡排序的原理,顾名 ...
- script标签的位置
1.在我们编写代码的时候,会在页面内使用<script>标签来写JS,虽然理论上script标签的位置放在哪里可以,但是还是有一点区别的. 2.为什么很多人把script标签放在底部: 初 ...
- SMO启发式选择
%% % svm 简单算法设计 --启发式选择 %% clc clear close all % step=0.05;error=1.2; % [data, label]=generate_sampl ...
- SharePoint 要一个多行文本类型字段为特殊类型的链接
1.插入在测试列表中的多行文本字段.名字叫做Content.例如下面的附图: 2.在Content字段里.加入一个Link.例如以下图: 3.尝试输入Notes格式的Link,例如以下图: 4.点击O ...
- Mysql查看连接端口及版本
C:\Users\Administrator>mysql -uroot -pEnter password: *****Welcome to the MySQL monitor. Commands ...