import networkx as nx

def cami_indirecte_1(g, a, b, c):
    if (a in g and b in g and c in g and
        nx.has_path(g, a, c) and nx.has_path(g, c, b)):
        l1 = nx.shortest_path(g, a, c)
        l2 = nx.shortest_path(g, c, b)
        cami = l1[:-1] + l2
    else:
        cami = []
    return cami

def cami_indirecte_2(g, a, b, c):
    try:
        l1 = nx.shortest_path(g, a, c)
        l2 = nx.shortest_path(g, c, b)
        cami = l1[:-1] + l2
    except (nx.exception.NetworkXError, nx.exception.NetworkXNoPath,
            nx.exception.NodeNotFound):
        cami = []
    return cami


# Tria la solució
cami_indirecte =  cami_indirecte_1
# cami_indirecte =  cami_indirecte_2
