Skip to main content
Back to problems
Codeforces
Medium
Arrays
Geometry
Math
Dima and Continuous Line

Determine whether a set of line segments forms one continuous, non-breaking line.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Problem

You are given several line segments drawn on a plane. Decide whether they can be viewed as one continuous line without gaps or breaks.

A valid continuous line means that the segments connect in a way that the whole figure is connected as a single chain or loop, with no isolated piece.

What to check

  • All segments belong to one connected structure.
  • There are no disconnected components.
  • Endpoints are the only places where segments may meet.

Task

Return whether the drawn segments form a continuous line.

Input Format

  • The input describes a collection of line segments.
  • Each segment is defined by its endpoints.
  • The exact input encoding may vary by platform, but the task is to determine if the whole set is connected as one continuous drawing.

Output Format

  • Print YES if the segments form one continuous line.
  • Otherwise print NO.

Constraints

  • Assume standard integer coordinates.
  • The number of segments is small enough for an O(n2)O(n^2) or similar geometric connectivity check.
  • Use exact geometric reasoning for intersections and shared endpoints.
Examples
Sample cases returned by the problem API.

Example 1

Input

3
0 0 2 0
2 0 4 0
4 0 6 0

Output

YES

Explanation

All three segments touch end-to-end, so together they form one continuous line.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.