Republic of Korea
Time limit1sMemory limit128 MB
Count crossing pairs among K straight highways linking numbered east and west coast cities, using inversion counting.
- Level
Medium4 of 10
- Topics
- Sorting, Divide and conquer, Array
- Solved
- No attempts yet
Problem
The Republic of Korea lies on the Korean Peninsula in East Asia. It is bordered by sea on three sides: the West Sea to the west, the East Sea to the east, and the South Sea to the south.
There are cities on the east coast and cities on the west coast. (, ) On each coast the cities are numbered from , in order from north to south.
The newly inaugurated president wants to build highways connecting the east coast to the west coast. Each highway is a straight road that connects exactly one east-coast city to exactly one west-coast city. (In reality a perfectly straight road bores and tires drivers and can cause accidents, so roads are deliberately given slopes and curves to prevent this.)
A rest stop is built at every point where two highways cross. At most highways cross at any single point. Given the highways, write a program that counts the number of points at which highways cross.
Input
The first line contains the number of test cases .
For each test case, the first line contains three integers , , and , where is the number of highways.
Each of the next lines describes one highway with two integers: the first is the number of the east-coast city it connects, and the second is the number of the west-coast city.
The number of highways is at most , and only inputs whose answer is at most are given.
Output
For each test case, print one line in the form Test case X: Y, where is the test case number (starting from ) and is the number of points at which the highways cross.