Get Luffy Out * HDU - 1816(2 - sat 妈的 智障)
题意:
英语限制了我的行动力。。。。就是两个钥匙不能同时用,两个锁至少开一个
建个图 二分就好了。。。emm。。。。dfs 开头low 写成sccno 然后生活失去希望。。。
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define pd(a) printf("%d\n", a);
#define plld(a) printf("%lld\n", a);
#define pc(a) printf("%c\n", a);
#define ps(a) printf("%s\n", a);
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
int n, m;
vector<int> G[maxn];
int sccno[maxn], vis[maxn], low[maxn], scc_cnt, scc_clock;
stack<int> S; struct node
{
int x, y;
}Node[maxn], Edge[maxn];
void init()
{
mem(sccno, );
mem(vis, );
mem(low, );
scc_clock = scc_cnt = ;
for(int i = ; i < maxn; i++) G[i].clear();
} void dfs(int u)
{
vis[u] = low[u] = ++scc_clock;
S.push(u);
for(int i = ; i < G[u].size(); i++)
{
int v = G[u][i];
if(!vis[v])
{
dfs(v);
low[u] = min(low[v], low[u]);
}
else if(!sccno[v])
low[u] = min(low[u], vis[v]);
}
if(vis[u] == low[u])
{
scc_cnt++;
for(;;)
{
int x = S.top(); S.pop();
sccno[x] = scc_cnt;
if(x == u) break;
}
}
} bool check()
{
for(int i = ; i <= n * - ; i += )
if(sccno[i] == sccno[i + ])
{
return false;
}
return true;
} void build(int mid)
{
for(int i = ; i < n; i++)
{
int u = Edge[i].x, v = Edge[i].y;
G[u << | ].push_back(v << );
G[v << | ].push_back(u << );
} for(int i = ; i < mid; i++)
{
int u = Node[i].x, v = Node[i].y;
G[u << ].push_back(v << | );
G[v << ].push_back(u << | );
}
} int main()
{
int u, v;
while(cin >> n >> m && n + m)
{
init();
for(int i = ; i < n; i++)
{
cin >> Edge[i].x >> Edge[i].y;
}
for(int i = ; i < m; i++)
{
cin >> Node[i].x >> Node[i].y;
}
int l = , r = m, ans;
while(l <= r)
{
init();
int mid = (l + r) / ;
build(mid);
for(int i = ; i <= n * - ; i++)
if(!vis[i]) dfs(i);
if(check()) l = mid + ;
else r = mid - ;
}
cout << r << endl; } return ;
}
Get Luffy Out * HDU - 1816(2 - sat 妈的 智障)的更多相关文章
- Go Deeper HDU - 3715(2 - sat 水题 妈的 智障)
Go Deeper Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- HDU 1816, POJ 2723 Get Luffy Out(2-sat)
HDU 1816, POJ 2723 Get Luffy Out pid=1816" target="_blank" style="">题目链接 ...
- HDU - 1816 Get Luffy Out *(二分 + 2-SAT)
题目大意:有N串钥匙,M对锁.每串钥匙仅仅能选择当中一把.怎样选择,才干使开的锁达到最大(锁仅仅能按顺序一对一对开.仅仅要开了当中一个锁就可以) 解题思路:这题跟HDU - 3715 Go Deepe ...
- HDU 1816 Get Luffy Out *
Get Luffy Out * Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- POJ 2723 HDU 1816 Get Luffy Out
二分答案 + 2-SAT验证 #include<cstdio> #include<cstring> #include<cmath> #include<stac ...
- hdu 1816(二分+2-sat)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1816 思路:首先将每把钥匙i拆成两个点i和i+2n,分别表示选与不选,对于被分成n对的钥匙,由于只能选 ...
- hdu 4115 (2—SAT)
题意:两个人石头剪刀布,一个人的出法已确定,另一个人的出法有一定约束,某两次要相同或者不同,问你第二个人能否全部都不失败. 思路:根据Bob出的情况,我们可以确定每次Alice有两种方案. R与P,S ...
- UWP开发入门(十二)——神器Live Visual Tree
很久以前,我们就有Snoop这样的工具实时修改.查看正在运行的WPF程序,那时候调个样式,修改个模板,相当滋润.随着历史的车轮陷进WP的泥潭中,无论WP7的Silverlight还是WP8.1的run ...
- Freemarker 浅析 (zhuan)
http://blog.csdn.net/marksinoberg/article/details/52006311 ***************************************** ...
随机推荐
- pycharm 报错:pycharm please specify a different SDK name
我在给项目配虚拟环境里的解释器的时候有没有遇到过这个问题的啊,就是一个正常的项目,解释器忽然丢了,解释器是配在虚拟环境里面的,再去选择解释器就一直报这个错,给现有项目添加虚拟环境的时候也是报这个错—— ...
- Ubuntu18.04安装netstat
一.简介 Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memb ...
- No enclosing instance of type is accessible. Must qualify the allocation with an enclosing instance of type LeadRestControllerTest (e.g. x.new A() where x is an instance of ).
java - No enclosing instance is accessible. Must qualify the allocation with an enclosing instance o ...
- Nginx Configuring HTTPS servers
Configuring HTTPS servershttp://nginx.org/en/docs/http/configuring_https_servers.html Configuring HT ...
- python中$和@基础笔记
python 2.4以后,增加了@符号修饰函数对函数进行修饰,python3.0/2.6又增加了对类的修饰. $ 在正则表达式中,匹配一个字符串的末尾.(参考http://www.runoob.com ...
- [转帖]system()、exec()、fork()三个与进程有关的函数的比较
system().exec().fork()三个与进程有关的函数的比较 https://www.cnblogs.com/qingergege/p/6601807.html 启动新进程(system函数 ...
- SpringMVC+Spring+Mybatis+AngularJS 多规格保存示例代码
insert时拿到最新增加的id值 绑定参数 js 实体类 Service实现类 Controller
- zookeeper的安装和启动教程
zookeeper的安装和启动 zookeeper安装包所在目录: 上传文件到虚拟机.现在本地新建一个目录setup,将zookeeper压缩包复制进去. ALT+P打开一个标签,操作如下put命令. ...
- <转>Python中的新式/经典类的查找方式
在学习到深度和广度的时候,懵了很久.后来看到这篇文章,恍然大悟.写的很好.特意转过来. 经典类: 只要有父类, 就会沿着一直找, 即使已经找过了~ 新式类: 在类继承的多个类拥有共同父类的情况下, 会 ...
- 剑指offer(15)
题目: 定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1)). 书中的思路: 按照这个思路我们很容易写出以下代码: import java.util.S ...