二分图匹配

首先有个定理:最长反链=最小链覆盖

最小链覆盖可以重复经过点

所以我们不能直接建图

那么我们用floyd判断是否相连

然后建图就行了

#include<bits/stdc++.h>
using namespace std;
const int N = , inf = 1e9;
int rd()
{
int x = , f = ; char c = getchar();
while(c < '' || c > '') { if(c == '-') f = -; c = getchar(); }
while(c >= '' && c <= '') { x = x * + c - ''; c = getchar(); }
return x * f;
}
int n, m, k, D, source, sink, cnt = , tot;
int a[N], d[N], head[N], iter[N], Map[N][N];
struct edge {
int nxt, to, f;
} e[N * N];
bool bfs()
{
queue<int> q;
memset(d, -, sizeof(d));
d[source] = ;
q.push(source);
while(!q.empty())
{
int u = q.front();
q.pop();
for(int i = head[u]; i; i = e[i].nxt) if(d[e[i].to] == - && e[i].f)
{
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
return d[sink] != -;
}
int dfs(int u, int delta)
{
if(u == sink) return delta;
int ret = ;
for(int &i = iter[u]; i && delta; i = e[i].nxt) if(d[e[i].to] == d[u] + && e[i].f)
{
int x = dfs(e[i].to, min(delta, e[i].f));
ret += x;
delta -= x;
e[i].f -= x;
e[i ^ ].f += x;
}
return ret;
}
int dinic()
{
int ret = ;
while(bfs())
{
for(int i = source; i <= sink; ++i) iter[i] = head[i];
ret += dfs(source, inf);
}
return ret;
}
void link(int u, int v, int f)
{
e[++cnt].nxt = head[u];
head[u] = cnt;
e[cnt].to = v;
e[cnt].f = f;
}
void insert(int u, int v, int f)
{
link(u, v, f);
link(v, u, );
}
int main()
{
scanf("%d%d", &n, &m);
sink = * n + ;
for(int i = ; i <= m; ++i)
{
int u, v;
scanf("%d%d", &u, &v);
Map[u][v] = ;
}
for(int k = ; k <= n; ++k)
{
insert(source, k, );
insert(k + n, sink, );
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j)
Map[i][j] |= (Map[i][k] & Map[k][j]);
}
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j) if(Map[i][j])
insert(i, j + n, );
printf("%d\n", n - dinic());
return ;
}

bzoj2718的更多相关文章

  1. BZOJ-1143&&BZOJ-2718 祭祀river&&毕业旅行 最长反链(Floyed传递闭包+二分图匹配)

    蛋蛋安利的双倍经验题 1143: [CTSC2008]祭祀river Time Limit: 10 Sec Memory Limit: 162 MB Submit: 1901 Solved: 951 ...

  2. BZOJ2718: [Violet 4]毕业旅行

    2718: [Violet 4]毕业旅行 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 229  Solved: 126[Submit][Status ...

  3. [转载]hzwer的bzoj题单

    counter: 664BZOJ1601 BZOJ1003 BZOJ1002 BZOJ1192 BZOJ1303 BZOJ1270 BZOJ3039 BZOJ1191 BZOJ1059 BZOJ120 ...

  4. BZOJ刷题列表【转载于hzwer】

    沿着黄学长的步伐~~ 红色为已刷,黑色为未刷,看我多久能搞完吧... Update on 7.26 :之前咕了好久...(足见博主的flag是多么emmm......)这几天开始会抽时间刷的,每天几道 ...

随机推荐

  1. 百度地图SDK调试SDKInitializer.initialize(getApplicationContext())错误

    首先描写叙述下问题出现的原因.開始的时候写了一个百度地图SDK的demo来试功能,由于最開始用的是Eclipse自带的AVD来调试,一切正常. 都能够正常验证,可是由于受不了重复的重新启动AVD设备, ...

  2. odoo税金处理

    税金可以设置为'税金包含在价格中',或者'税金不包含在价格中'.         在税金计算处理过程中,odoo会将价格/金额按 total_included/ total_exincluded 分开 ...

  3. HRBUST2030(dfs)

    成语接龙 Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %lld , %llu Java class nam ...

  4. poj3211 Washing Clothes

    Description Dearboy was so busy recently that now he has piles of clothes to wash. Luckily, he has a ...

  5. Block系列1:初识block

    //-------1.定义函数----- //1.函数 int sum(int a,int b) { return a+b; } //------------------2.声明--------- / ...

  6. 记录一次在 VirtualBox的添加共享windows文件后,发现没有共享文件的事

    在VirtualBox设置完桥接添加ip后,在设备中添加共享windows文件,“e:\work ”,发现共享目录没有文件.使用了各种reboot之后,还是没有发现共享文件夹,重新设置还是不行,用mo ...

  7. 解析java.math.BigInteger类——构造函数

    最早由于做作业,结识了java的BigInrger类.读着读着,越来越觉得有趣.后来作业做完,也不忍丢下它,索性把全部代码研究一遍. 开始的时候,一个上午时间最多读懂2个方法.但是还是有滋有味的坚持了 ...

  8. scikit-learn:4.2. Feature extraction(特征提取,不是特征选择)

    http://scikit-learn.org/stable/modules/feature_extraction.html 带病在网吧里. ..... 写.求支持. .. 1.首先澄清两个概念:特征 ...

  9. postgresql的show databases、show tables、describe table操作

    1.相当与mysql的show databases; select datname from pg_database; 2.相当于mysql的show tables; SELECT table_nam ...

  10. LeetCode(82)题解: Remove Duplicates from Sorted List II

    https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ 题目: Given a sorted linked list, ...