Select whole hierarchy from different parents at the same time
I found the solution so others can benefit from this as well.
After the las line just add:
for obj in selected:
    bpy.context.view_layer.objects.active = obj
    bpy.ops.object.select_grouped(extend=True, type='CHILDREN_RECURSIVE')
    bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM')