HDU ---- (3118) arbiter (construct a bipartite graph)

Source: Internet
Author: User
Arbiter

Time Limit: 1000/1000 MS (Java/others) memory limit: 131072/131072 K (Java/Others)
Total submission (s): 800 accepted submission (s): 410


Problem descriptionarbiter is a kind of starship in the StarCraft science-fiction series. the arbiter-class starship is A protoss warship specializing in providing psychic support. arbiters were crewed exclusively by judicators; unlike other warships that were manned predominantly by Templar. the judicator used the arbiter as a base to provide support using space-time manipulation.
Arbiters cocould weaken space-time, tearing rifle in the fabric of space-time, creating a vortex linking another location to the Arbiter's location. this cocould be used to move personnel over long distances between stars.
In the meantime of widely used arbiter to transfer, kmxs, the Captain of one arbiter, was warning that some person had got a serious mental disorder after the trip on his arbiter. by using mice as model animals, he found the sake, it's because of chirality!
Every person has chirality, either left-handed or right-handed. actually all the persons must live with the food which has the same chirality. when one person took arbiter from one star to another one, his chirality will be changed (from left-handed to right-handed or from right-handed to left-handed ). if a person took a long trip and finally got back to his own star, however, his chirality might be changed to the opposite state other than his original, which wowould cause fatal mental disorder, or even death.
Kmxs has the channels map among the starts and he need to prohibit minimum number of channels from traveling so that wherever a person starts his traveling from when he gets his original star he'll be safe. kmxs turns to your help.

 

Inputthe first line of input consists of an integer T, indicating the number of test cases.
The first line of each case consists of two integers n and M, indicating the number of stars and the number of channels. each of the next M lines indicates one channel (u, v) which means there is a bidirectional channel between star U and star V (U is not equal to V ).

 

Outputoutput one integer on a single line for each case, indicating the minimum number of channels kmxs must prohibit to avoid mental disorder.

Constraints
0 <t <= 10
0 <= n <= 15 0 <= m <= 300
0 <= u, v <n and there may be more than one channel between two stars.

 

Sample input13 30 11 22 0

 

Sample output1

 

Source 2009 Asia Wuhan Regional Contest online: arbiter is a space ship in Starcraft sci-fi series. The arbitration-level space ship is a battle ship of the god family, dedicated to providing spiritual support. Unlike the personnel of other warships, the main class is the warrior class, and the arbitrator carries the ruling class. The ruler is based on the arbitration and uses time-space control to provide support. The arbitrator can overcome the limitations of time and space, tear the time and space, create cracks, create a vortex hole, and connect another space to the space where the arbitrator is located. It can be used to transport people and bridge the distance between stars. While the arbitration was widely used for transportation, kmxs, the ship's captain, issued a warning that some people had serious mental confusion after completing their journey on his ship. He used mice for animal experiments and found out the reason: the "chiral" in biochemistry "! Each person has a chiral, either left or right. In fact, everyone's survival must rely on the same chiral food. When a person takes the arbitration from one planet to another, his or her chiral will change (from the left-handed to the right-hand, or from the right-hand to the left-hand .) If a person makes a long journey and finally returns to his planet, his or her hand may change to the opposite of his or her, which may lead to fatal mental disorder or even death. Kmxs has a route map between planets. He needs to prohibit the minimum number of channels from passing through, so that no matter where a person starts, it will be safe when he returns to his planet. Kmxs asks for your help. The first line of input contains an integer T, indicating the number of test cases. The first line of each case contains two integers n and M, indicating the number of planets and the number of waterways. The next M line represents a channel, and each (u, v) represents a two-way channel between the planet U and the planet V (U is not equal to V ). Output the results of each test case output a line with an integer representing the minimum number of channels that kmxs must deny to avoid mental disorder. Constraints 0 <t <= 10 0 <= n <= 15 0 <= m <= 300 0 <= u, v <n can have more than one channel between two planets. sample input 13 30 11 22 0 sample output 1 is obvious: this means that you can go from any planet to another planet, but every planet has a chiral ..... if we want to find out, any planet cannot be transmitted back to the planet through an odd number of times... that is, the odd ring cannot be formed .. we know that the necessary and sufficient condition for a bipartite graph is that there are at least two vertices, And the Loop Length of each vertex is an even number... so we only need to erase the edges to form a bipartite graph .,... code:
1 # include <cstring> 2 # include <cstdio> 3 const int maxn = 305; 4 int AA [maxn], BB [maxn]; 5 Int n, m; 6 int main () {7 int test; 8 // freopen ("test. in "," r ", stdin); 9 scanf (" % d ", & Test); 10 while (test --) {11 scanf (" % d ", & N, & M); 12 for (INT I = 0; I <m; I ++) {13 scanf ("% d", AA + I, BB + I); 14} 15 int ans = m + 2; 16 for (INT I = 0; I <(1 <n); I ++) // In 2 ^ n cases, either left or right 17 {18 int CNT = 0; 19 for (Int J = 0; j <m; j ++) {20 if (I> AA [J]) % 2) = (I> BB [J]) % 2) // belongs to the same world, indicating that there is an odd ring, 21 CNT ++; 22} 23 if (ANS> CNT) ans = CNT; 24} 25 printf ("% d \ n", ANS); 26} 27 return 0; 28}
View code

 

HDU ---- (3118) arbiter (construct a bipartite graph)

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.