Sessions in BSU
Sessions in BSU
有n项考试。每项考试给定两个时间,你可以任意选择一个时间。每个时间点只能考一场考试,请问在最优情况下最早考完的时间。n<=1e6。
把题目抽象成图论模型:在每项考试的两个时间点之间连边,那么问题就变成了:给所有边定向,使得每个时间点的入度至多为1,请你让入度为1的点的编号的最大值最小。
然后,我们可以发现只有基环树和树是合法的。对于基环树,取最大值;对于树,去最小值,然后对所有值取max就行了。
exp:如果在代码里用全局变量的话,就不用写两个dfs了。所以说别忘记在dfs之前想想返回值能不能用全局变量记录!也想想能不能用引用来记录。
#include <map>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef pair<int, int> pi;
const int maxn=2e6+5;
int n, a, b, ans;
struct Edge{
int to, nxt;
}e[maxn*2];
int cntedge, fir[maxn];
void addedge(int x, int y){
Edge &ed=e[++cntedge];
ed.to=y; ed.nxt=fir[x]; fir[x]=cntedge;
}
int vis[maxn], cnte, cntn;
void dfs(int now){
++cntn; vis[now]=1;
for (int i=fir[now]; i; i=e[i].nxt){
++cnte;
if (!vis[e[i].to]) dfs(e[i].to);
}
}
int vis2[maxn];
pi dfs2(int now){
if (vis2[now]) return make_pair(0, 0);
pi re=make_pair(now, 0), tmp;
vis2[now]=1;
for (int i=fir[now]; i; i=e[i].nxt){
tmp=dfs2(e[i].to);
if (tmp.first>re.first){
re.second=re.first;
re.first=tmp.first;
} else if (tmp.first>re.second)
re.second=tmp.first;
if (tmp.second>re.second) re.second=tmp.second;
}
return re;
}
int a1[maxn], a2[maxn], bb[maxn], mm, trans[maxn];
int main(){
scanf("%d", &n); int x, y;
for (int i=1; i<=n; ++i){
scanf("%d %d", &a1[i], &a2[i]);
bb[++mm]=a1[i]; bb[++mm]=a2[i]; }
sort(bb+1, bb+mm+1); mm=unique(bb+1, bb+mm+1)-bb-1;
for (int i=1; i<=n; ++i){
x=lower_bound(bb+1, bb+mm+1, a1[i])-bb;
y=lower_bound(bb+1, bb+mm+1, a2[i])-bb;
addedge(x, y); addedge(y, x);
}
int ans=0; pi tmp;
for (int i=1; i<=mm; ++i){
if (vis[i]) continue;
cntn=cnte=0; dfs(i); cnte/=2;
if (cnte>cntn){ puts("-1"); return 0; }
tmp=dfs2(i);
if (cnte==cntn) ans=max(ans, tmp.first);
else ans=max(ans, tmp.second);
}
printf("%d\n", bb[ans]);
return 0;
}
Sessions in BSU的更多相关文章
- How do servlets work-Instantiation, sessions, shared variables and multithreading[reproduced]
When the servletcontainer (like Apache Tomcat) starts up, it will deploy and load all webapplication ...
- Django 1.10 中文文档------3.3.8 会话sessions
django支持匿名会话.它将数据存放在服务器端,并抽象cookies的发送和接收过程.cookie包含一个会话ID而不是数据本身(除非你使用的是基于后端的cookie). 3.3.8.1 启用会话 ...
- logoff remote desktop sessions via command line tools
This trick I learned from my one of ex-college. In Windows servers, only two remote desktop session ...
- 启动tomcat时,报错:IOException while loading persisted sessions: java.io.EOFException解决方法
报错原因:加载持久化session错误,tomcat加载时读取的文件是是*.ser,session序列化文件,文件的位置是tomcat\work\Catalina\localhost,找到sessio ...
- Exception loading sessions from persistent storage
严重: Exception loading sessions from persistent storage java.io.EOFException 删除Tomcat里面的work/Catalina ...
- Error: Error setting TTL index on collection : sessions
Error: Error setting TTL index on collection : sessions 一.步骤一: 这个问题一般是直接升级 mongodb和connect-mongo的版本为 ...
- Exception loading sessions from persistent storage 这个问题的解决
现在经常在做一个项目时重启时会报: 严重: Exception loading sessions from persistent storage的问题. 这个问题的原因是tomcat的session持 ...
- sessions 表的架构过程
对于 PHP 开发来说,保存会话用 MySQL 是一个非常不错的选择.MySQL 提供一种建立在内存中的表类型 Heap,如果每条会话数据量很小的话,可以考虑用这种类型的表来进一步优化性能.但是 He ...
- tomcat启动报错:IOException while loading persisted sessions: java.io.EOFException.
tomcat启动错误代码: 严重: IOException while loading persisted sessions: java.io.EOFException java.io.EOFExce ...
随机推荐
- java添加背景图片
总结:我们通常实现添加背景图片很容易,但是再添加按钮组件就会覆盖图片.原因是: 有先后啊.setlayout();与布局有很大关系 请调试代码的时候,仔细揣摩.我晕了 还可以添加文本框,密码框 fra ...
- [置顶]
都是类型惹的祸——小心unsigned
正如我们所知道的,编程语句都有很多的基本数据类型,如char,inf,float等等,而在C和C++中还有一个特殊的类型就是无符号数,它由unsigned修饰,如unsigned int等.大家有没想 ...
- SQL属性第一个值不被选中,属性默认第一个值
把 Please Choose Color 属性名设置为不可选的 UPDATE `products_attributes` SET `attributes_display_only` = '1' WH ...
- Celery-4.1 用户指南: Daemonization (系统守护进程)
Generic init-scripts 查看Celery发布里的 extra/generic-init.d/ 文件夹. 这个文件夹中包含了celery worker 程序的通用bash初始化脚本,可 ...
- js和jQuery常用选择器
笔者觉得js是前台基础中的基础,而其选择器则是js基础中的基础,因长期使用框架导致js生疏,所有查资料,回顾一下js的常用选择器: 1.document.getElementById("id ...
- startactivityforresult使用
与startactivity基本相同,不过需要传入(intent,int)第二个int为请求ID,用来识别 在该activity中还应该重写nActivityResult(int requestCod ...
- 使用HttpClient进行Post通信
---------------siwuxie095 首先到 Apache官网 下载相关的库文件 Apache官网:http://www.apac ...
- JS 中的数组遍历方式效率比较
JS数组遍历,基本就是for,forin,foreach,forof,map等等一些方法,以下介绍几种本文分析用到的数组遍历方式以及进行性能分析对比 第一种:普通for循环 代码如下: ; j < ...
- 触摸屏、X11去掉鼠标
cursor disable in X11 Last updated 8 years ago 摘自:http://www.noah.org/wiki/cursor_disable_in_X11 Whe ...
- unix 下 shell 遍历指定范围内的日期
UNIX下遍历日期,date 没有 -d 的参数,所以需要自己处理. 下面使用时差的方法进行计算,遍历的日期是降序的 #!/usr/bin/ksh . $HOME/.profile timelag= ...