Hihocoder #1127: Minimum point coverage and maximum independent set of binary graphs

Source: Internet
Author: User

The main topic: to find the minimum point of two-dimensional coverage and maximum independent set.

Title Analysis: If a point is selected, then all edges connected to this point are overwritten, so that the minimum point set that all edges are overwritten is called the minimum point overlay, which equals the maximum match, and the largest point set with no edges connected between any two points is called the maximum independent set, which equals the total number of nodes minus the maximum number of matches.

The code is as follows:

# include<iostream># include<cstdio># include<cmath># include<vector># include<list># include<queue># include<map># include<set># include<cstring># include<algorithm> using namespace std;const int n=1000;const int inf=1000000000;const double inf=1e20;int N,m;int link[n+5];vector<int& Gt;e[n+5];int mark[n+5];bool Match (int x) {for (int i=0;i<e[x].size (); ++i) {int y=e[x][i];if (mark[y]) continue;mark[ Y]=1;if (link[y]==-1| | Match (Link[y])) {Link[y]=x;return true;}} return false;} int main () {while (~scanf ("%d%d", &n,&m)) {for (int i=0;i<n;++i) e[i].clear (), int a,b;while (m--) {scanf ("%d%d ", &a,&b);--a,--B;e[a].push_back (b); E[b].push_back (a);} int Cnt=0;memset (link,-1,sizeof), for (int i=0;i<n;++i) {memset (mark,0,sizeof (Mark)), if (Match (i)) ++cnt;} cnt/=2;printf ("%d\n%d\n", cnt,n-cnt);} return 0;}

  

Hihocoder #1127: Minimum point coverage and maximum independent set of binary graphs

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.