Awkward Group
Time limit5sMemory limit256 MB
Count the subsets whose largest inner closeness is smaller than every closeness to the outside.
- Level
Medium7 of 10
- Topics
- Minimum spanning tree, Union-find, Sorting
- Solved
- No attempts yet
Problem
A community is made up of people who live in a small town. Two people in may be friends, or they may never have met. The closeness of two distinct people and is a value , and .
Call a subset of a group, and write for the number of people in it. is an awkward group if is neither nor and the largest closeness between two distinct members of is strictly smaller than every closeness between a member of and someone outside . That is, is awkward when it satisfies both conditions:
Given the closeness of every pair of distinct people, write a program that counts the awkward groups of .
For example, suppose holds three people , and . The groups with are , and . If the closeness values are , and , the only awkward group among them is , so the answer is .
Input
Read from standard input. The first line holds the number of test cases . The first line of each test case holds , the number of people in the community (). The people are numbered to . The next lines hold the closeness values. Line holds integers separated by single spaces, where is , the closeness of person and person (, ).
Output
Write to standard output. Print exactly one line for each test case. The line holds the number of awkward groups of .