Assign each pilot to at most one plane they can fly to maximize the number of planes sent.
Medium4GraphDFSNo attempts yetTime limit1sMemory limit256 MBWhen Germany was split into a part controlled by the Allies (France, England, the USA) and a part controlled by the Soviet Union, Berlin was divided as well. West Berlin belonged to West Germany, but the whole of Berlin sat inside East German territory, so no land route connected West Berlin to the rest of West Germany. After West Germany introduced a new currency, the Soviet Union cut every land and water connection from West Germany to West Berlin from 1948 to 1949. The Allies flew supplies from West Germany into West Berlin instead, and that operation is called the Air Bridge. Gail Halvorsen is credited with starting the practice: to entertain the children waiting for the planes, pilots dropped chocolate and other candy on small homemade parachutes. The planes became known as candy bombers.
Running an Air Bridge means solving several optimization problems. One of them is how to assign the planes and pilots you have so that as much weight as possible reaches the destination. Assume every plane carries the same amount of cargo. The goal is then to fly as many planes as you can.
You are given the list of planes and pilots currently available, and for each pilot the list of planes that pilot is able to fly. A pilot flies at most one plane, and a plane is flown by at most one pilot. Compute the largest number of planes that can be sent.
The first line contains the number of data sets K, with K≥1. Then K data sets follow in the format below.
The first line of a data set contains two integers m and n. Here m is the number of available planes, n is the number of pilots, and 0≤m,n≤200. Then follow n lines, one per pilot. The first number on line i is the number mi of planes that pilot i is capable of flying, with 0≤mi≤m. It is followed by mi integers, each between 1 and m and all distinct, which are the planes pilot i can fly.
For each data set, first print Data Set x: on a line of its own, where x is the number of the data set, counting from 1. On the next line print the largest number of planes you can send. Print one blank line after the output of each data set.