"Network Flow" POJ 3041 asteroids binary map maximum match-"Challenge Program Design Competition" Example

Source: Internet
Author: User

Learning network flow in ing ... As a beginner practice is essential ~ ~ ~ Composition method because the book is very detailed, so simply say

The beam as the vertex of the graph, the asteroid as the edge of the connection vertex, the map, because the minimum vertex coverage is equal to the maximum matching of two graphs , so the maximum matching of the binary graph can be obtained.

Adjacency Matrix, Dfs seek augmented path, Hungarian algorithm

Adjacency Matrix: Complexity O (n^3)

If using adjacency table: Complexity O (n*m)

#include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include < algorithm> #include <set> #include <map> #include <stack> #include <vector> #include < queue> #include <string> #include <sstream> #define EPS 1e-9#define all (x) X.begin (), X.end () #define INS (x ) Inserter (X,x.begin ()) #define for (I,J,K) for (int i=j;i<=k;i++) using namespace Std;typedef long Long ll;int i,j,k,n,m , X,y,t,ans,big,cas,match[505],g[505][505],r,c;bool flag,vis[505];bool Hungary (int u)//start looking for augmented path {for (int i=1;i<=) from U            n;i++) {if (G[u][i]&&!vis[i])//g array storage adjacency matrix, Match[i] represents the node of the current node I match {vis[i]=1; if (match[i]==0| |        Hungary (Match[i])) return match[i]=u; }} return 0;}    int main () {scanf ("%d%d", &n,&k);        for (i=1;i<=k;i++) {scanf ("%d%d", &r,&c);    G[r][c]=1;        } ans=0; /* Hungarian algorithm process-find the augmented path */for (i=1;i<=n;i++) {memset (Vis,0,sizeof (VIS));    If (Hungary (i)) ans++;    }/* Search for End */printf ("%d\n", ans); return 0;}

  

"Network Flow" POJ 3041 asteroids binary map maximum match-"Challenge Program Design Competition" Example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.