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 ...
随机推荐
- (转)heX——基于 HTML5 和 Node.JS 开发桌面应用
本文转载自:http://techblog.youdao.com/?p=685 简介:heX,一个允许你采用前端技术(HTML,CSS,JavaScript)开发桌面应用软件的跨平台解决方案.是你开发 ...
- 使用内省的方式操作JavaBean
import java.beans.BeanInfo; import java.beans.Introspector; import java.beans.PropertyDescriptor; im ...
- kubernetes 学习 ingress
ingress是Kubernetes 暴露服务的一种方式. Ingress由两部分组成:Ingress Controller 和 Ingress 服务. Ingress Contronler ...
- CentOS 7.2 部署Rsync + Lsyncd服务实现文件实时同步/备份 (二)
发送端配置: 一.配置密钥 1. 主/从服务器之间启用基于密钥的身份验证.登录发送端服务器并用 " ssh-keygen " 命令生成公共或私有的密钥. 2. 使用 " ...
- Codeforces Round #310 (Div. 2)556ABCDE
https://github.com/Anoxxx/OI/blob/master/Anoxx/Contest10 github自取
- leetcode860
使用C++进行编码: bool lemonadeChange(vector<int>& bills) { ; ; ; int N = bills.size(); ; i < ...
- C语言学习笔记--指针阅读技巧
1. 指针阅读技巧:右左法则 (1)从最里层的圆括号中未定义的标示符看起 (2)首先往右看,再往左看 (3)遇到圆括号或方括号时可以确定部分类型,并调转方向 (4)重复 2.3 步骤,直到阅读结束 注 ...
- 线段树教做人系列(2)HDU 4867 XOR
题意:给你一个数组a,长度为.有两种操作.一种是改变数组的某个元素的值,一种是满足某种条件的数组b有多少种.条件是:b[i] <= a[i],并且b[1]^b[2]...^b[n] = k的数组 ...
- Emgu cv3.0.0 图像收集
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- 【摘自张宴的"实战:Nginx"】nginx配置
user nobody;worker_processes 2; #error_log logs/error.log;error_log logs/error.log notice;#error_log ...