Poj 1466 girls and boys (Maximum Independent Set)

Source: Internet
Author: User

Link: poj 1466

There are n students, each of which has a relationship with some people. Now you need to find the maximum number of students so that they do not matter.

Idea: Find the maximum independent set, the maximum independent set = points-the maximum number of matches
Analysis: when creating a picture, it should be a boy's point while a girl's point. But the question does not mention gender, and each point can only be split into two points, one is treated as a male point, the other is a female point, and then the edge is connected. because the relationship is mutual, edge duplication occurs. That is to say, the edge set is twice as long as the current one, resulting in the largest matching to double the original. Therefore, the maximum independent set = point-Maximum number of matching/2.

# Include <stdio. h> # include <string. h> int N, edge [510] [510], link [510], used [510]; int DFS (int pos) {int I; for (I = 0; I <n; I ++) {If (edge [POS] [I] &! Used [I]) {used [I] = 1; if (link [I] =-1 | DFS (link [I]) {link [I] = Pos; return 1 ;}} return 0 ;}int main () {int I, j, A, B, S, M; while (scanf ("% d", & N )! = EOF) {memset (edge, 0, sizeof (edge); for (I = 0; I <n; I ++) {scanf ("% d: (% d) ", & A, & M); For (j = 0; j <m; j ++) {scanf (" % d ", & B ); edge [a] [B] = 1; // graph} memset (link,-1, sizeof (Link); s = 0; for (I = 0; I <n; I ++) {memset (used, 0, sizeof (used); S + = DFS (I);} printf ("% d \ n ", n-S/2); // remember to subtract half of the maximum number of matches} return 0 ;}



Poj 1466 girls and boys (Maximum Independent Set)

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.