"POJ 3041" asteroids (minimum point coverage)

Source: Internet
Author: User

Each time you choose to clear an asteroid on one row or column. Choose at least a few times.

The rows and columns are abstracted into points, the I behavior node i+n, the J column is the node J, each planet is an edge, connected to the row.

The problem is then transformed into a minimum point overlay. The minimum point of a binary graph overrides = = maximum match.

#include <cstdio> #include <cstring>const int n=505<<1;int n,vis[n],link[n],g[n][n];int find (int u) { for (int i=1; i<=n*2; i++) if (G[u][i]&&!vis[i]) {vis[i]=1;if (!link[i]| | Find (Link[i])) {Link[i]=u;return 1;}} return 0;} int solve () {memset (link,0,sizeof link), int ans=0;for (int i=1;i<=n;i++) {memset (vis,0,sizeof Vis), if (Find (i)) ans++ ;} return ans;} int main () {int m,u,v;scanf ("%d%d", &n,&m), memset (g,0,sizeof g), while (m--) {scanf ("%d%d", &u,&v); g[u+ N][v]=g[v][u+n]=1;} printf ("%d\n", Solve ());}

  

"POJ 3041" asteroids (minimum point coverage)

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.