#K95722. Largest Connected Component Sum
Largest Connected Component Sum
Largest Connected Component Sum
You are given an undirected graph with N nodes and M edges. Each node has an associated integer value. Your task is to find the connected component with the largest sum of node values and output that sum.
The graph is given in the following format: the first line contains two integers N and M. The next M lines each contain two integers representing an edge between two nodes (0-indexed). The last line contains N integers where the i-th integer is the value associated with node i.
Note: There might be isolated nodes (with no edges) and multiple disconnected components. Use appropriate graph traversal methods (such as BFS or DFS) to solve the problem.
inputFormat
The first line contains two integers N and M separated by space.
The next M lines each contain two integers u and v representing an undirected edge between nodes u and v (0-indexed).
The last line contains N space-separated integers, where the i-th integer represents the value of node i.
outputFormat
Output a single integer which is the sum of the node values of the largest connected component in the graph.
## sample4 2
0 1
2 3
1 2 3 4
7