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 ...
随机推荐
- SPARC T4 RAID Setup (ZT)
http://www.confignotes.com/2013/09/sparc-t4-raid-setup/ How to configure a RAID volume with the inte ...
- 问题:C# TrimEnd 去掉最后的逗号;结果: C#中 TrimEnd()用法
C#中 TrimEnd()用法 ①去除最后的逗号 string str=ab,cd,ef,; str=str.TrimEnd(new char[] { ',' }); 返回结果则是:ab,cd,ef ...
- 【Android 多媒体应用】使用 TTS
import java.util.Locale; import android.app.Activity; import android.os.Bundle; import android.speec ...
- 使用spring-loaded实现应用热部署
作为一名Java开发者您是否会遇到这种情况:新增一个方法或字段必须重启tomcat才能对其进行调试? 有没有办法使得不重启tomcat就能调试呢.spring-loaded就可以. spring-lo ...
- UAC(User Agent Client) 和 UAS(User Agent Server)
SIP协议采用Client/Server模型.每一个请求(Request)触发服务器的一个操作:每个操作被称为方法(Method):每个请求除了指明具体方法外,还携带了一系列的头域(Header fi ...
- Emulator PANIC: Could not open: AVD2.3.1
这是这两年的sdk才需要这样,以前这样根本没错的 在环境变量 里面增加一个系统变量ANDROID_SDK_HOME,值就是当前的系统用户文件夹的位置.比如c:\\Users\xxx(不要加.andro ...
- 一段PHP异常
这是我写的一段代码,里面通过PHP异常功能,实现报错时显示出错代码所在行.当使用者操作出错时,截图给我,我可以很快得去追踪和排查错误! public function added_business_s ...
- Codeforces 464E The Classic Problem (最短路 + 主席树 + hash)
题意及思路 这个题加深了我对主席树的理解,是个好题.每次更新某个点的距离时,是以之前对这个点的插入操作形成的线段树为基础,在O(logn)的时间中造出了一颗新的线段树,相比直接创建n颗线段树更省时间. ...
- c# 类的初步认识
这里我们把类分为三种: String类(字符串类):Math类(数学类):DateTime类(时间日期类). 在使用类时注意 在输入的过程中代码前面会出现一些符号(紫色立方体代表方法,函数和黑色扳手 ...
- Blender 工具使用——显示键盘和鼠标操作
Blender 工具使用--显示键盘和鼠标操作 Blender自己本身就带有显示按键和鼠标的功能,就是3D View: Screencast Keys插件. 打开 File(文件) -> Use ...