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 ...
随机推荐
- canvas图像以及剪切
图像篇: 代码: 1 /** 2 * Created by Administrator on 2016/1/28. 3 */ 4 function draw (id){ 5 var canvas = ...
- C# EntityFramwork(Model First)使用要点
本文介绍EntityFramework使用方法 Entity Framework的注意点 由于安装和操作的细节讲起来很琐碎,这部分只罗列出难点,其他细节请自行查阅 安装细节 Pluralize or ...
- 无人零售的黑科技:RFID技术
无人零售的黑科技:RFID技术说起最近的热门话题,“无人零售商店”当属其一.自去年底,亚马逊推出第一家无人实体超市Amazon Go,到阿里.京东.大润发等各大企业纷纷加入,无人商店被推上了风口浪尖. ...
- Win7无法访问Windows共享文件夹
解决方法如下 On the Windows 7 machine: Run secpol.msc Drill down through Local Policies | Security Options ...
- Android getWidth和getMeasuredWidth的区别
getWidth 得到的事某个View的实际尺寸. getMeasuredWidth 得到的是某个View想要在parent view里面占的大小 相比你也见过这样的解释,听起来这样的解释也是云里雾里 ...
- WebSocket详解(一):初步认识WebSocket技术
1.什么是Socket?什么是WebSocket? 对于第1次听说WebSocket技术的人来说,两者有什么区别?websocket是仅仅将socket的概念移植到浏览器中的实现吗? 我们知道,在网络 ...
- koa2 原生链接mysql
1.安装mysql $ npm install mysql 2.代码示例: const mysql = require("mysql"); // mysql.Promise = g ...
- Gearman 分布式的异步任务分发框架
What is Gearman? Gearman provides a generic application framework to farm out work to other machines ...
- ROS Learning-020 learning_tf-04(编程)让turtle2 海龟跟随turtle1海龟,并绕着 turtle1海龟转圈 (Python版)
ROS Indigo learning_tf-04 (编程)让 turtle2 海龟跟随 turtle1 海龟,并绕着 turtle1 海龟转圈 (Python版) 我使用的虚拟机软件:VMware ...
- PCL—点云分割(RanSaC)低层次点云处理
博客转载自:http://blog.csdn.net/app_12062011/article/details/78131318 点云分割 点云分割可谓点云处理的精髓,也是三维图像相对二维图像最大优势 ...