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 ...
随机推荐
- 学习Linux相关书籍
要推荐的书,我在<那两年炼就的Android内功修养>这篇文章中有提到,这里再列一下出来: 语言类: <深度探索C++对象模型>,对应的英文版是<Inside C+++ ...
- java代码equals方法
package com.bc; public class Test_6 { // 我们知道java中的每个类都继承自Object类,equals是Object方法之一 String name; int ...
- Rails的静态资源管理(六)—— Asset Pipeline缓存存储方式、预处理、升级等
官方文档:http://guides.ruby-china.org/asset_pipeline.html http://guides.rubyonrails.org/asset_pipeline.h ...
- 微信小程序的组件总结
本文介绍微信小程序的组件 视图容器 基础内容 表单组件 导航组件 媒体组件 视图容器 view 布局容器 <view hover-class='bg'>222</view> 可 ...
- IOCP编程原理(转)
在我的博客之前写了很多关于IOCP的“行云流水”似的看了让人发狂的文章,尤其是几篇关于 IOCP加线程池文章,更是让一些功力不够深厚的初学IOCP者,有种吐血的感觉.为了让大家能够立刻提升内力修为,并 ...
- createprocess并行运算
#include "stdafx.h"#include "windows.h"#include <iostream> using namespace ...
- pa15-三省吾身
序号 项 1 凡事提前10分钟 凡事提前10分钟,会让你有充裕的时间应对可能的突发事件,更加从容. 试着把起床闹钟提前10分钟,你就会发现你出门不必急匆匆,早饭也可慢慢享用,一整天的状态也 ...
- HDLM命令dlnkmgr详解之二__help/clear
1.help操作 主要显示命令的帮助信息. 显示所有操作的帮助信息 -bash-3.2# dlnkmgr help dlnkmgr: Format dlnkmgr { clear | help | o ...
- jackson 进行json与java对象转换 之一
代码无真相,为了最简单的说明,我直接上代码. public class User { private String name; private Gender gender; private List& ...
- XE Button Color
XE Button Color,FMX Button 颜色 也可以放个rectangle+Glyph控件. http://blogs.embarcadero.com/sarinadupont/2014 ...