Our friend Victor participates as an instructor in an environmental volunteer program. His boss asked Victor to distribute N T-shirts to Mvolunteers, one T-shirt each volunteer, where N is multiple of six, and NM. There are the same number of T-shirts of each one of the six available sizes: XXL, XL, L, M , S, and XS. Victor has a little problem because only two sizes of the T-shirts suit each volunteer.
You must write a program to decide if Victor can distribute T-shirts in such a way that all volunteers get a T-shirt that suit them. If N M, there can be some remaining T-shirts.
The first line of the input contains the number of test cases. For each test case, there is a line with two numbers N and M. N is multiple of 6, 1N36, and indicates the number of T-shirts. Number M, 1M30, indicates the number of volunteers, with NM. Subsequently, M lines are listed where each line contains, separated by one space, the two sizes that suit each volunteer (XXL, XL, L, M , S, or XS).
For each test case you are to print a line containing YES if there is, at least, one distribution where T-shirts suit all volunteers, or NO, in other case.
3 18 6 L XL XL L XXL XL S XS M S M L 6 4 S XL L S L XL L XL 6 1 L M
YES NO YES
題意:
有n(n是6的倍數)件衣服,6種尺碼,每種尺碼的衣服數量相同,有m個人,每人有兩種能穿的尺碼,問每個人是否都有衣服穿。
分析:
顯然的二分圖。每個人向其合適的尺碼連邊,容量為1;增加源點和匯點,源點向每個人連邊,容量為1,每種尺碼向匯點連邊,容量為該種尺碼衣服的數量(n/6)。在上圖中跑最大流,如果滿流則所有人都有衣服穿。
/* * * Author : fcbruce * * Date : 2014-09-04 20:47:21 * */ #include#include #include #include #include #include #include #include #include #include #include #include #include #include
#include