#P2210. [USACO13OPEN] Haywire B
[USACO13OPEN] Haywire B
Description
Farmer John has cows (, and is even). They set up a homemade system that allows cows and their friends to communicate through lines protected by hay bales.
Each cow in the pasture has exactly friends, and the cows must be arranged in a single row of hay bales.
A line of length occupies exactly hay bales to protect it. For example, if two cows are placed at hay bales and and they are friends, then we need hay bales to build the line that connects them.
Assume that every pair of friends must be connected by a separate line, and we may rearrange the cows arbitrarily. Compute the minimum total number of hay bales required to build all the lines.
Input Format
Line : An integer . For convenience, the cows are numbered .
Lines : Each line contains three integers in . The numbers on line are the indices of cow ’s three friends. Obviously, if cow is one of cow ’s three friends, then cow is also one of cow ’s three friends.
Output Format
A single integer representing the minimum number of hay bales required to build the lines.
6
6 2 5
1 3 4
4 2 6
5 3 2
4 6 1
1 5 3
17
Hint
Sample explanation: the best arrangement of the cows is , in which case we need only hay bales.
Translated by ChatGPT 5
京公网安备 11011102002149号