Giant components of graph

Dear all, Is there any function to get a subset of graph that have largest connected component using Graphs.jl (version >= 1.4.1)? I only found function connected_components that return a list of connected vertices?

In function connected_components

g = SimpleGraph([0 1 0 0 0; 1 0 1 0 0; 0 1 0 0 0; 0 0 0 0 1; 0 0 0 1 0]);

connected_components(g)
2-element Array{Array{Int64,1},1}:
 [1, 2, 3]
 [4, 5]

What I need is a get_largest_component_graph

g = SimpleGraph([0 1 0 0 0; 1 0 1 0 0; 0 1 0 0 0; 0 0 0 0 1; 0 0 0 1 0]);

giant_component_graph = get_largest_component_graph(g)

Is there any idea to create this get_largest_component_graph? Thank you very much

How about this?

function main_component(g)
    c = connected_components(g)
    _, i = findmax(length.(c))
    g[c[i]]
end

julia> g = erdos_renyi(1000, 1000)
{1000, 1000} undirected simple Int64 graph

julia> main_component(g)
{802, 970} undirected simple Int64 graph
1 Like

Great! Thank you so much for the solution.