Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 4788 | Accepted: 2327 |
Description
In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pick some kids to play a game, which need that all players know each other. You are to help to find maximum number of kids the teacher can pick.
Input
The input consists of multiple test cases. Each test case starts with a line containing three integers
G, B (1 ≤ G, B ≤ 200) and M (0 ≤ M ≤ G × B), which is the number of girls, the number of boys and
the number of pairs of girl and boy who know each other, respectively.
Each of the following M lines contains two integers X and Y (1 ≤ X≤ G,1 ≤ Y ≤ B), which indicates that girl X and boy Y know each other.
The girls are numbered from 1 to G and the boys are numbered from 1 to B.
The last test case is followed by a line containing three zeros.
Output
For each test case, print a line containing the test case number( beginning with 1) followed by a integer which is the maximum number of kids the teacher can pick.
Sample Input
2 3 3 1 1 1 2 2 3 2 3 5 1 1 1 2 2 1 2 2 2 3 0 0 0
Sample Output
Case 1: 3 Case 2: 4
题意:
给出 G (1 ~ 200)和 B (1 ~ 200)分别是女孩的个数和男孩的个数。后给出 M 对关系 G 对 B,代表 G 号女孩认识 B 号男孩,女孩与女孩之间相互认识,男孩与男孩之间相互认识。求最大的人数,使里面的任意两个人之间都相互认识。
思路:
二分图最大匹配。匈牙利算法。给出的关系是相互认识的关系,那么求出来的最大独立集代表的就是里面的人相互不认识。如果给出的是相互不认识的关系,那么求出来的最大独立集就是里面的人相互都认识。故将图反过来建,求其最大独立集即可。
AC:
#include <cstdio> #include <string.h> using namespace std; int vn,un; int w[205][205],vis[205],linker[205]; bool dfs(int u) { for(int v = 1;v <= vn;v++) if(w[u][v] && !vis[v]) { vis[v] = 1; if(linker[v] == -1 || dfs(linker[v])) { linker[v] = u; return true; } } return false; } int hungary() { int res = 0; memset(linker,-1,sizeof(linker)); for(int u = 1;u <= un;u++) { memset(vis,0,sizeof(vis)); if(dfs(u)) res++; } return res; } int main() { int m,ans = 0; while(~scanf("%d%d%d",&un,&vn,&m) && (un + vn + m)) { ans++; for(int i = 1;i <= un;i++) for(int j = 1;j <= vn;j++) w[i][j] = 1; while(m--) { int f,t; scanf("%d%d",&f,&t); w[f][t] = 0; } printf("Case %d: ",ans); printf("%d\n",vn + un - hungary()); } return 0; }
相关推荐
是对网上这种算法相关描述的一些总结,附带了北大上的几个练习题目,我自己通过仔细钻研比较透彻的掌握了这门算法,记得08年ACM/ICPC合肥赛区一个kindergarten(幼儿园)的题目就是我AC的。相信看过的人都会受益匪浅
KinderGarten,刘坤的作品,作为以后的资料参考用
Kindergarten游戏安装包,亲测可用。Kindergarten游戏安装包,亲测可用。
一个用于将kindergarten整合到VueJS应用程序中的VueJS2.0插件
vue-kindergarten, 为 Vue,Vuex,Vue路由器和Nuxt提供模块化安全 kindergarten幼儿园 简介幼儿园是一个用于 VueJS 2.0的插件,它将幼儿园插件集成到你的VueJS应用程序中。 它可以以帮助你在非常模块化的方式下授权...
Wordpress Kindergarten模板
幼儿园管理系统,按年龄排序后分别输出姓名、性别、年龄、身高、体重、出生日期
kindergarten
Prediction of kindergarten reading success from preschool report of parents 304 Psychology in the Schools, July , 1976, Vol. I S , No. 3. of individual children. However, the hypothesis suggested ...
The kindergarten auditory screening test as a predictor of reading disability A Comparison of Three Measures 399 REFERENCES ARTHUR, G. The Arthur Adaptation of the Leiter Ii~ternational ...
The development of kindergarten behavior rating scales for the prediction of learning and behavior disorders THE DEVELOPMENT OF KINDERGARTEN BEHAVIOR RATING SCALES FOR THE PREDICTION OF LEARNING ...
幼儿园游戏 apk 链接: ://www.dropbox.com/s/kcli6z8vwgrgrl1/KindergartenGame.apk dl
司机端车辆认证及技能认证 提现 流水列表 评价列表
Effects of length of school day on kindergarten school performance and parent satisfaction Psychologv in the Schools 1982, 19, 238-242 EFFECTS O F LENGTH O F SCHOOL DAY ON KINDERGARTEN SCHOOL ...
kindergarten-backend
nikoniko_kindergarten
Kindergarten_Backend
ASP.NET MVC开发的幼儿园网站,完整功能,无数据库。包括首页、关于园所、新闻中心、精彩活动、宝宝园地、校园风采、联系我们等网站页面及后台。欢迎下载评价!
Characteristics of at-risk children in transitional and regular kindergarten programs Human Figure Drawings of Preschool Children 325 SWENSON, C. H. (1968). Empirical evaluation of human figure ...
Kindergarten reasoning and achievement in grades K-3 Psychology in fhe Schools Volume 20. J u l y . 1983 KINDERGARTEN REASONING AND ACHIEVEMENT IN GRADES K-3 VIRGINIA M. SILLIPHANT’ Holland ...