Cablemaxxing


Submit solution

Points: 1
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python, Rust

YOU: "You were stationed very close to the crime scene. Did you hear any noises coming from backstage at the time of the incident?"

LUKAZ: "Nah, I had no idea. Look, I was stressed, okay? I wasn't exactly cataloguing every sound in the building.

There was clattering from the kitchen the whole time. Glasses clinking from the bar. And about twelve frantic computer science students just yammering over each other. You can see why I might not be able to isolate whatever it is you're looking for.

Do you understand how long I spent dialling in the audio? Hours! And now it's all for nothing. I mean, rest in peace, Kevin. But come on!"

Lukaz is a very dedicated AV (Audio-Visual) guy.

To avoid last-minute issues with the display, he wants to use the longest cable he has available. Unfortunately, all the cables are mixed and tangled together, making the best cable to use a bit unclear.

Lukaz's cables are represented by n straight segments of wire on a 2D plane. Two wires belong to the same cable if they share a common endpoint, in other words, a cable is a maximal group of wires connected through shared endpoints. The length of a cable is the sum of the lengths of its wires.

What is the length of the longest cable that Lukaz can use?

Input

The first line contains a single integer n (1 \leq n \leq 10^5), the number of wire segments that Lukaz has.

The next n lines each contain two integer points (a_x, a_y) and (b_x, b_y) (1 \leq a_x, a_y, b_x, b_y \leq 10^5), indicating that there is a straight segment of wire between points (a_x, a_y) and (b_x, b_y).

  • All wires are unique.
  • (a_x, a_y) \neq (b_x, b_y) for each wire.
  • Any point may appear at most twice across all wire endpoints.
  • Wires connect only at shared endpoints. Two wires that cross or overlap without sharing an endpoint are not connected.
  • The wires do not form a cycle. Together with the previous conditions, this guarantees that every cable is a simple, non-branching path.

Output

Output the length of the longest cable. Submit so it is correct to exactly 12 decimal places.

Example

Input 1
10
1 1 3 3
3 3 4 6
4 6 5 4
3 4 1 5
1 5 6 5
2 4 2 1
2 1 6 4
6 4 6 2
6 2 4 2
4 2 5 3
Output 1
13.414213562373

The longest cable is the red one shown below, at 13.41 units.

Image 1

Input 2
6
1 1 6 6
4 3 3 3
3 3 3 4
3 4 5 4
5 4 5 2
5 2 3 2
Output 2
8.000000000000

The longest cable is the yellow one shown below, at 8 units.

Image 2

Input 3
5
1 4 4 1
2 4 5 1
2 5 5 2
3 5 6 2
3 6 6 3
Output 3
4.242640687119

All cables are the same length, at 4.24 units.

Image 3


Comments


  • 0
    Peter  commented on July 18, 2026, 6:19 a.m.

    hi