#C958. Graph Connectivity Checker
Graph Connectivity Checker
Graph Connectivity Checker
Given a set of points and a list of undirected edges connecting these points, determine whether the entire graph is connected.
A graph is considered connected if, for every pair of distinct vertices \(u\) and \(v\), there exists a path from \(u\) to \(v\). Formally, for \(n > 0\), the graph is connected if for all \(u, v \in V\) there is a sequence of edges connecting \(u\) and \(v\) (i.e., a path exists between any two vertices). If there are no points (i.e., \(n = 0\)), the graph is deemed trivially connected.
The input provides both the coordinates of points (which are supplementary information) and the edges between them. Your task is to check if all points in the graph belong to a single connected component.
inputFormat
The input is given via stdin and has the following format:
n m x1 y1 x2 y2 ... xn yn u1 v1 u2 v2 ... um vm
Where:
n
is the number of points.m
is the number of edges.- The next
n
lines each contain two integers representing the coordinates of a point (\(x_i, y_i\)). - The following
m
lines each contain two integersu
andv
(0-indexed) indicating an undirected edge between pointu
and pointv
.
outputFormat
Output a single line to stdout containing either True
if the graph is connected, or False
if it is not.
4 4
0 0
1 0
1 1
0 1
0 1
1 2
2 3
3 0
True