Implement the functionality to count the number of connected segments in an undirected graph defined by a set of nodes and edges. The function needs to operate under the following specifications:
Functionality
Create a function count_connected_segments(n, edges) that takes in:
n (integer): The number of nodes in the graph (0-indexed).
edges (list of tuples): A list where each tuple consists of two integers representing an edge between two nodes. Nodes are represented by integers from 1 to n.
The function should return the total number of connected segments in the graph. A connected segment is defined as a contiguous sequence of connected nodes.
Input/Output Requirements
Input:
An integer n (1 ≤ n ≤ 1000) indicating the number of nodes.
A list of edges edges, where each edge connects two nodes (1-indexed) of the graph. Each tuple can be represented as (a, b) where 1 ≤ a, b ≤ n and a ≠ b.
Output:
An integer representing the count of connected segments in the graph.
Implementation Details
The function must handle cases with no edges gracefully, returning zero connected segments for such cases.
All nodes should be examined, and the function should utilize efficient data structures and algorithms to ensure performance within the constraints.
File Requirement
Write the solution in a file named /app/solution.py. The file should contain the defined function count_connected_segments and any necessary import statements.
Please ensure the solution is properly tested for edge cases and adheres to the provided specifications.