Guest User

Graph

a guest
May 10th, 2015
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. Bruce and the Chocolates
  2. Max. Marks 100
  3. Early this morning, I found our little Bruce sitting on a bench alone in the park. I sat beside him to ask where has he dropped his smile this morning?
  4.  
  5. Bruce: "Oh, Hi.. I love chocolates. (Who doesn't? ). It's chocolate day in school, and I forgot! Everyone is bringing chocolates. We play a game on this day, where the teacher makes pair of students and the students in each pair share their chocolates. I will have to go empty handed and hence, won't get paired :( "
  6.  
  7. "That's okay ,Bruce. You can ask your friends to share with you"
  8.  
  9. Bruce: " I did a smarter thing, I talked to my Mathematics teacher. I'm her favorite! She agreed that I could do the pairing! and from every pair , I could take 'x' number of chocolates, where x is the greatest number of chocolates that divides the number of chocolates with both the students. Now, I don't know how do I pair them! Not everyone can be paired with everyone, friendship issues. Can you help me out?"
  10.  
  11. You are given the number of chocolates with each student and all the possible pairs of the form (i,j) where ith and jth student can be paired. Help Bruce pair the students, so as to maximize the number of chocolates he can have .
  12.  
  13. You may assume:
  14.  
  15. No pairs should overlap. No student is left alone (except Bruce).
  16.  
  17. Total number of students in class is always odd.
  18.  
  19. No one is absent on the Chocolate Day!
  20.  
  21. For a possible pairing (i,j) , ( i+j )mod 2 >0
  22.  
  23. Input
  24.  
  25. First line of the input contains T (1<=T<=10) denoting the number of test cases. T testcases follow. For each test case, the first line contains two space-separated integers 'n' (1<=n<200) and 'm' (m>=0) , the total number of students in the class and the number of possible pairings.
  26.  
  27. Next line contains 'n-1' integers, where Ai (1<=Ai<=10000) is the number of chocolates with the i'th student.
  28.  
  29. The following m lines contain the description of possible pairs. The k-th line contains two space-separated integers Ik, Jk (1<=Ik,Jk<=n-1 ) .
  30.  
  31. Output
  32.  
  33. Output the maximum number of chocolates that Bruce can have.
  34.  
  35.  
  36. Sample Input(Plaintext Link)
  37. 2
  38. 7 9
  39. 1 24 9 18 3 7
  40. 1 2
  41. 1 4
  42. 1 6
  43. 3 2
  44. 3 4
  45. 3 6
  46. 5 2
  47. 5 4
  48. 5 6
  49. 5 1
  50. 2 7 21 3
  51. 1 4
  52. Sample Output(Plaintext Link)
  53. 13
  54. 1
Advertisement
Add Comment
Please, Sign In to add comment