Codey and Toy Kingdom
https://www.hackerrank.com/contests/codenection-2024-preliminary-round-open-category/challenges/cn24-16
Question
Codey bought a new set of toys, which includes islands and bridges, and wanted to build a dream toy kingdom using them.
First, Codey arranged islands in a circle, numbered from to in a clockwise direction, and connected each pair of adjacent islands with a bridge. Although this version of the toy kingdom allows travel between any two islands using a series of bridges, it is inefficient. To improve travel between distant islands, Codey decided to build bridges between islands that are not adjacent.
Codey used the remaining bridges to connect different pairs of islands. Each island will have exactly one extra bridge connected to it. For each pair of bridges that intersect, the complexity of the toy kingdom increases by .
Help Codey determine the total complexity of the toy kingdom.
Input Format
The first line contains an integer n
, which there are islands.
The next n
lines contain two space-separated integers, and , representing the -th bridge between islands and .
Constraints
Each island will have exactly one extra bridge connected to it.
Output Format
Output the total complexity of the toy kingdom.
Sample Inputs:
Last updated