LOJ6000 「网络流 24 题
来源:互联网 发布:ubuntu优麒麟 编辑:程序博客网 时间:2024/06/05 19:13
大家都很强, 可与之共勉 。
题意:
裸的二分图坠大匹配。
题解:
我萌来想想怎么建图呢(初级向)
首先我萌要一个超级原点
之后我萌对于二分图左边的点,源点
之后我萌对于二分图右边的点,汇点
然后就跑个坠大流。
挺萌的
# include <bits/stdc++.h># define N 1010class Network {private : struct edge { int to, w, nxt ; edge ( ) { } edge ( int to, int w, int nxt ) : to ( to ), w ( w ), nxt ( nxt ) { } } g [N << 1] ; int head [N], cur [N], ecnt ; int S, T , dep [N] ; inline int dfs ( int u, int a ) { if ( u == T || ! a ) return a ; int flow = 0, v, f ; for ( int& i = cur [u] ; i ; i = g [i].nxt ) { v = g [i].to ; if ( dep [v] == dep [u] + 1 ) { f = dfs ( v, std :: min ( g [i].w, a - flow ) ) ; g [i].w -= f, g [i ^ 1].w += f ; flow += f ; if ( a == flow ) return a ; } } if ( ! flow ) dep [u] = -1 ; return flow ; } inline bool bfs ( int S, int T ) { static std :: queue < int > q ; memset ( dep, 0, sizeof ( int ) * ( T + 1 ) ) ; dep [S] = 1 ; q.push ( S ) ; while ( ! q.empty ( ) ) { int u = q.front ( ) ; q.pop ( ) ; for ( int i = head [u] ; i ; i = g [i].nxt ) { int& v = g [i].to ; if ( g [i].w && ! dep [v] ) { dep [v] = dep [u] + 1 ; q.push ( v ) ; } } } return dep [T] ; }public : Network ( ) { ecnt = 1 ; } inline void add_edge ( int u, int v, int w ) { g [++ ecnt] = edge ( v, w, head [u] ) ; head [u] = ecnt ; g [++ ecnt] = edge ( u, 0, head [v] ) ; head [v] = ecnt ; } inline int dinic ( int S, int T ) { this -> S = S, this -> T = T ; int rt = 0 ; while ( bfs ( S, T ) ) { memcpy ( cur, head, sizeof ( int ) * ( T + 1 ) ) ; rt += dfs ( S, 0x3f3f3f3f ) ; } return rt ; }} Lazer ;int main ( ) { int n, m ; scanf ( "%d%d", & n, & m ) ; int a, b ; const int S = n + 1, T = n + 2 ; n -= m ; while ( ~ scanf ( "%d%d", & a, & b ) ) { // a < b ; Lazer.add_edge ( a, b, 0x3f3f3f3f ) ; } for ( int i = 1 ; i <= m ; ++ i ) Lazer.add_edge ( S, i, 1 ) ; for ( int i = 1 ; i <= n ; ++ i ) Lazer.add_edge ( i + m, T, 1 ) ; printf ( "%d\n", Lazer.dinic ( S, T ) ) ; return 0 ;}
阅读全文
0 0
- LOJ6000 「网络流 24 题
- loj6000 「网络流 24 题」搭配飞行员(二分图最大匹配)
- LOJ6000
- 【网络流】网络流24题
- [网络流]: 网络流24题
- 网络流24题
- 网络流24题
- 网络流24题
- 网络流24题
- 「网络流 24 题」试题库
- 「网络流 24 题」试题库
- LOJ6001 「网络流 24 题
- LOJ6002 「网络流 24 题
- LOJ6003 「网络流 24 题
- LOJ6004 「网络流 24 题
- LOJ6005 「网络流 24 题
- LOJ6006「网络流 24 题
- LOJ6007 「网络流 24 题
- 关于不支持多线程处理的并发问题
- bzoj1002
- mysql基础&重点知识总结及在python中的应用(2)
- C语言贪心算法之喷水装置(二)
- leetcode 372. Super Pow
- LOJ6000 「网络流 24 题
- Spring Bean生命周期
- CodeForces892B Wrath
- 程序员的8条宝贵经验!
- Golang简介
- HihoCoder
- 导航栏渐变方案收录二
- 如何快速获得自己的所有csdn博客地址
- LeetCode174. Dungeon Game