#P6857. Amazing John's Dream Bridge Challenge
Amazing John's Dream Bridge Challenge
Amazing John's Dream Bridge Challenge
Amazing John had n dreams. Every two distinct dreams are connected by exactly one bridge; there are no loops. When John traverses a bridge \(e_{u,v}\) (in either direction) for the first time, he earns 1 rest point. Note that each bridge can only be used once (regardless of direction). The journey terminates when John reaches a dream where all connecting bridges have already been traversed.
Determine the maximum rest points that can be obtained starting from any dream. In other words, given the complete graph \(K_n\) with n vertices and each edge giving 1 point when used (and each edge used at most once), find the maximum number of points that can be collected.
The answer can be formulated as follows:
- If \(n\) is odd, then an Eulerian cycle exists and John can traverse all edges, so the maximum rest points are \[ \frac{n \times (n-1)}{2} \].
- If \(n\) is even, an Eulerian trail does not exist in the original graph. However, by avoiding exactly \(\frac{n}{2} - 1\) bridges, John can achieve a trail that uses the remaining bridges. Hence, the maximum rest points are \[ \frac{n \times (n-1)}{2} - \frac{n}{2} + 1 \].
Note: When \(n=1\) there are no bridges, so the maximum rest points is 0.
inputFormat
The input consists of a single integer \(n\) (\(1 \le n \le 10^9\)), representing the number of dreams.
outputFormat
Output a single integer representing the maximum rest points obtainable.
sample
1
0