/**
[2-sat+二分]poj 2723 Get Luffy Out
有n组钥匙,每组只能用一把;m扇门只能按顺序开,每个门需两把钥匙任选一把开,问最多开几扇门
每个钥匙拆成用于不用两个点,则存在两种矛盾。
对于成对的钥匙,同时使用是矛盾的。
对于门上的钥匙,同时不使用是矛盾的。
二分答案的时候注意左右边界的情况
*/
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
#define N 4100
int key[N][2],door[N][2];
int n,nn,m;
vector<int> vec[N];
int id[N],pre[N],s[N],low[N],stop,cnt,scnt;
void tarjan(int v)
{
int t,minc = low[v] = pre[v] = cnt++;
vector<int>::iterator pv;
s[stop++] = v;
for(pv = vec[v].begin(); pv != vec[v].end(); ++pv)
{
if(-1 == pre[*pv])
tarjan(*pv);
if(low[