def f(u=0):
    if (not g.edges[u]):
        return 1
    s = [f(v) for v in g.edges[u]]
    return ((max(s) + min(s)) + 1)
def f(u=0):
    if (not g.edges[u]):
        return 1
    s = [f(v) for v in g.edges[u]]
    return ((max(s) + min(s)) + 1)