HDU2470 (Get-Together at Stockholm)

Source: Internet
Author: User
/*************************************** * ************* Question: peter invited A friend to his party, but the invited person must meet the following requirements: at least A person who knows and B does not know each other at the party; calculate the maximum number of people invited by him. algorithm: This is a water question based on the data volume given by the question. That is, find an invalid node through cyclic search and delete its corresponding relationship; continue searching until every node is valid; **************************************** * ************/# include <iostream> # include <cstdio> # include <cmath> # include <cstring> using namespace std; const int n= 111; struct relation {int know, unknow;} a [N]; int map [N] [N]; bool Visit [N]; int n, m; int A, B; int solve () {int res = n; while (1) {int flag = 1; for (int I = 0; I <n; I ++) {if (! Visit [I] & (a [I]. know <A | a [I]. unknow <B) {visit [I] = 1; res --; flag = 0; for (int j = 0; j <n; j ++) {if (! Visit [j]) {if (map [I] [j]) {a [j]. know --;} else a [j]. unknow -- ;}}}if (flag) break; // All nodes meet the condition} return res;} int main () {// freopen ("C: \ Users \ Administrator \ Desktop \ kd.txt "," r ", stdin); int tcase = 1; while (~ Scanf ("% d", & n, & m, & A, & B) {if (! N &&! M &&! A &&! B) break; memset (a, 0, sizeof (a); memset (map, 0, sizeof (map); memset (visit, 0, sizeof (visit )); for (int I = 0; I <m; I ++) {int u, v; scanf ("% d", & u, & v ); map [u] [v] = map [v] [u] = 1; a [u]. know ++; a [v]. know ++ ;}for (int I = 0; I <n; I ++) {a [I]. unknow = n-a [I]. know-1; // number of people not recognized = n-recognized and himself} printf ("Case # % d: % d \ n", tcase ++, solve ();} return 0 ;}

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.