F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Warfare

Time Limit: 8000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 379    Accepted Submission(s): 144


Problem Description
In the year 2240 a great war is taking place between the Earth Allied Forces (EAF) and the Mars Federation (MF). Until recently, none of the two major factions could gain the upper hand in the war. Because of a recent nancial crisis, both factions' resources are thinning out, and it appears that the MF is using this to their advantage to claim more territories over the EAF. In response to this, the EAF have decided to carry out its greatest operation since the start of the war: it will launch a simultaneous attack against all the MF bases that are scattered over the planet Mars. The EAF's forces mostly consist of mechs, which are huge bipedal, limbed vehicles with ying capabilities.
A typical MF base is built up as follows: The buildings that make up the base are positioned over one or multiple territories. Each of these territories is protected against outside attacks by impenetrable energy elds that are generated by shield towers. These shield towers are positioned around the territories they're supposed to protect.
Each shield tower is connected to at least one other tower via channels that are constructed above the ground. When these connected towers form a cycle, they generate an energy eld. However,if a channel in a cycle is destroyed so that the cycle is broken, the energy eld will disappear. The MF knows that if all energy elds disappear, the base will be easily overrun by the EAF forces. Therefore, the two towers that are connected by a channel protect the channel against armed forces. Each tower has defenses that can take down a given number of enemy mechs. Each channel can handle an attack by a certain number of enemy mechs before it collapses. This number is given by the amount of mechs that both towers, that the channel connects, can take down. Two towers cannot be connected by more than one channel.



(a) Two towers that are connected by a channel. The vertices represent the towers while the line is the channel that connects the towers. The amount of mechs needed to destroy the channel is the combined amount of mechs that the connected towers can take down.


However, attacking a channel on one side of the tower does not diminish the amount of mechs that it can take down on the other side of the tower.
Because the operation is a surprise attack, all attacks on the channels must happen simultaneously: all channels are taken down at the same moment.


(b) MF base with multiple energy elds. The vertices represent the towers while the lines are the channels that connect the towers. The numbers indicate how many mechs a tower can take down.



(c) In this case, the destruction of two channels will make all energy elds disappear. Four mechs will be lost in the battle.



All energy elds must be disabled in order to destroy a MF base. Tearing down all channels would make this happen, but would also require a lot of mechs to be sacri ced. The EAF has very little forces to spare and must therefore deploy its mechs as e cient as possible.
You have been tasked to write a program that will lead the EAF to victory. Given a graph of shield towers, determine which channels must be destroyed to make all energy elds disappear, in such a way that the least number of EAF mechs are lost during the battle.
 

Input
The first line of input consists of the positive integer number n, the number of test cases;
Then, for each test case:
A line containing the positive integer number m (2 < m <=100), the number of towers in the base;
Per tower two lines:
A line containing three positive integer numbers i (0 <= i <= m-1), ui(1<= ui <=50) and ci (1 <= ci <= m -1): the (identification) number of the tower, the amount of mechs that the tower can take down and the number of channels respectively. The numbers are separated by a space;
A line containing ci different positive integers, the towers that are connected to tower i. A tower cannot be connected to itself. The integers are separated by a space.
A given base will always be able to generate at least one energy field.

 

Output
For each test case, the output contains a line with one number: the minimum number of EAF mechs that will be lost during the battle to make all energy elds disappear.
 

Sample Input
1 3 0 1 2 1 2 1 2 2 0 2 2 3 2 0 1
 

Sample Output
3
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-20 00:22:16, Gzip enabled