Buggy python submission (verdict: Time Limit Exceeded):
#coding=UTF-8

def search(jun):
    global ans
    global R
    global rrCost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += rrCost[mae][ba]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])

mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono)-1) for mono in hyo]

michi=[]
for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])

    michi.append((A,B,C))
    michi.append((B,A,C))

rrCost=[]
for idx in range(0,R,1):
    rrCost.append([None]*R)

for idx in range(0,R,1):
    rrCost[idx][idx]=0

for idr in range(0,R,1):
    deCost=[None]*N
    deCost[r[idr]]=0
    
    miru=[]
    for mono in michi:
        if mono[0] == r[idr]:
            deCost[mono[1]]=mono[2]
            miru.append(mono[1])

            for myon in range(0,R,1):
                if mono[1] == r[myon]:
                    rrCost[idr][myon]=mono[2]
                    rrCost[myon][idr]=mono[2]

    while miru:
        nextmiru=[]
        try:
            rrmax=max(rrCost[idr])
        except:
            rrmax=None
            
        for me in miru:
            preCost=deCost[me]
            for mono in michi:
                if mono[0] == me:
                    tmpCost=preCost+mono[2]
                    if deCost[mono[1]]==None or deCost[mono[1]]>tmpCost:
                        if rrmax==None or tmpCost < rrmax:
                            deCost[mono[1]]=tmpCost
                            nextmiru.append(mono[1])
                            
                            for myon in range(0,R,1):
                                if mono[1] == r[myon]:
                                    rrCost[idr][myon]=tmpCost
                                    rrCost[myon][idr]=tmpCost

        miru=list(set(nextmiru))



ans=None
search([])
print(ans)


Fixed submission:
#coding=UTF-8

def search(jun):
    global ans
    global R
    global r
    global rCost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += rCost[mae][r[ba]]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])


mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono) -1 ) for mono in hyo]

michi=[]
for idx in range(0,N,1):
    michi.append([])

for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])
    michi[A].append((B,C))
    michi[B].append((A,C))


rCost=[]
for idr in range(0,R,1):
    Cost=[None]*N
    Cost[r[idr]]=0
    miru=[r[idr]]
    while miru:
        nextmiru=[]
        for toshi in miru:
            preCost=Cost[toshi]
            for (saki,sakiCost) in michi[toshi]:
                tmpCost=preCost+sakiCost
                if Cost[saki]==None or tmpCost < Cost[saki]:
                    Cost[saki]=tmpCost
                    nextmiru.append(saki)

        miru=list(set(nextmiru))
    rCost.append(Cost)

#for ko in rCost:
#    print(ko)

ans=None
search([])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#coding=UTF-8

def search(jun):
    global ans
    global R
    global rrCost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += rrCost[mae][ba]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])

mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono)-1) for mono in hyo]

michi=[]
for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])

    michi.append((A,B,C))
    michi.append((B,A,C))

rrCost=[]
for idx in range(0,R,1):
    rrCost.append([None]*R)

for idx in range(0,R,1):
    rrCost[idx][idx]=0

for idr in range(0,R,1):
    deCost=[None]*N
    deCost[r[idr]]=0
    
    miru=[]
    for mono in michi:
        if mono[0] == r[idr]:
            deCost[mono[1]]=mono[2]
            miru.append(mono[1])

    while miru:
        nextmiru=[]

        for me in miru:
            preCost=deCost[me]
            for mono in michi:
                if mono[0] == me:
                    tmpCost=preCost+mono[2]
                    if deCost[mono[1]]==None or deCost[mono[1]]>tmpCost:
                        deCost[mono[1]]=tmpCost
                        nextmiru.append(mono[1])

        miru=list(set(nextmiru))

    for idx in range(0,R,1):
        rrCost[idr][idx]=deCost[r[idx]]
        rrCost[idx][idr]=deCost[r[idx]]


ans=None
search([])
print(ans)


Fixed submission:
#coding=UTF-8

def search(jun):
    global ans
    global R
    global r
    global rCost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += rCost[mae][r[ba]]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])


mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono) -1 ) for mono in hyo]

michi=[]
for idx in range(0,N,1):
    michi.append([])

for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])
    michi[A].append((B,C))
    michi[B].append((A,C))


rCost=[]
for idr in range(0,R,1):
    Cost=[None]*N
    Cost[r[idr]]=0
    miru=[r[idr]]
    while miru:
        nextmiru=[]
        for toshi in miru:
            preCost=Cost[toshi]
            for (saki,sakiCost) in michi[toshi]:
                tmpCost=preCost+sakiCost
                if Cost[saki]==None or tmpCost < Cost[saki]:
                    Cost[saki]=tmpCost
                    nextmiru.append(saki)

        miru=list(set(nextmiru))
    rCost.append(Cost)

#for ko in rCost:
#    print(ko)

ans=None
search([])
print(ans)

Buggy python submission (verdict: Runtime Error):
#coding=UTF-8

def search(jun):
    global ans
    global R
    global rrCost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += rrCost[mae][ba]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])

mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono)-1) for mono in hyo]

michi=[]
for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])

    michi.append((A,B,C))
    michi.append((B,A,C))

rrCost=[]
for idx in range(0,R,1):
    rrCost.append([None]*R)

for idx in range(0,R,1):
    rrCost[idx][idx]=0

for idr in range(0,R,1):
    deCost=[None]*N
    deCost[r[idr]]=0
    
    miru=[]
    for mono in michi:
        if mono[0] == r[idr]:
            deCost[mono[1]]=mono[2]
            miru.append(mono[1])

    while miru:
        nextmiru=[]

        for me in miru:
            preCost=deCost[me]
            for mono in michi:
                if mono[0] == me:
                    tmpCost=preCost+mono[2]
                    if deCost[mono[1]]==None or deCost[mono[1]]>tmpCost:
                        deCost[mono[1]]=tmpCost
                        nextmiru.append(mono[2])

        miru=list(set(nextmiru))

    for idx in range(0,R,1):
        rrCost[idr][idx]=deCost[r[idx]]
        rrCost[idx][idr]=deCost[r[idx]]


ans=None
search([])
print(ans)


Fixed submission:
#coding=UTF-8

def search(jun):
    global ans
    global R
    global r
    global rCost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += rCost[mae][r[ba]]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])


mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono) -1 ) for mono in hyo]

michi=[]
for idx in range(0,N,1):
    michi.append([])

for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])
    michi[A].append((B,C))
    michi[B].append((A,C))


rCost=[]
for idr in range(0,R,1):
    Cost=[None]*N
    Cost[r[idr]]=0
    miru=[r[idr]]
    while miru:
        nextmiru=[]
        for toshi in miru:
            preCost=Cost[toshi]
            for (saki,sakiCost) in michi[toshi]:
                tmpCost=preCost+sakiCost
                if Cost[saki]==None or tmpCost < Cost[saki]:
                    Cost[saki]=tmpCost
                    nextmiru.append(saki)

        miru=list(set(nextmiru))
    rCost.append(Cost)

#for ko in rCost:
#    print(ko)

ans=None
search([])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#coding=UTF-8

def search(jun):
    global ans
    global R
    global Kost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += Kost[r[mae]][r[ba]]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])

mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono)-1) for mono in hyo]

Kost=[]
for idx in range(0,N,1):
    Kost.append([None]*N)

for idx in range(0,N,1):
    Kost[idx][idx]=0

miru=[]
for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])

    Kost[A][B]=C
    Kost[B][A]=C
    miru.append((A,B,C))
    miru.append((B,A,C))

while miru:
    nextmiru=[]
    for idx in range(0,N,1):
        for keiro in miru:
            tui=Kost[keiro[1]][idx]
            if tui==None:
                continue

            tmpKost=keiro[2]+tui
            if Kost[keiro[0]][idx]==None or tmpKost < Kost[keiro[0]][idx]:
                Kost[keiro[0]][idx]=tmpKost
                nextmiru.append((keiro[0],idx,tmpKost))
    miru=nextmiru

#for gyo in Kost:
#    print(gyo)

ans=None
search([])
print(ans)


Fixed submission:
#coding=UTF-8

def search(jun):
    global ans
    global R
    global r
    global rCost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += rCost[mae][r[ba]]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])


mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono) -1 ) for mono in hyo]

michi=[]
for idx in range(0,N,1):
    michi.append([])

for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])
    michi[A].append((B,C))
    michi[B].append((A,C))


rCost=[]
for idr in range(0,R,1):
    Cost=[None]*N
    Cost[r[idr]]=0
    miru=[r[idr]]
    while miru:
        nextmiru=[]
        for toshi in miru:
            preCost=Cost[toshi]
            for (saki,sakiCost) in michi[toshi]:
                tmpCost=preCost+sakiCost
                if Cost[saki]==None or tmpCost < Cost[saki]:
                    Cost[saki]=tmpCost
                    nextmiru.append(saki)

        miru=list(set(nextmiru))
    rCost.append(Cost)

#for ko in rCost:
#    print(ko)

ans=None
search([])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#coding=UTF-8

def search(jun):
    global ans
    global R
    global Kost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += Kost[r[mae]][r[ba]]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])

mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono)-1) for mono in hyo]

Kost=[]
for idx in range(0,N,1):
    Kost.append([None]*N)

for idx in range(0,N,1):
    Kost[idx][idx]=0


for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])

    Kost[A][B]=C
    Kost[B][A]=C

changed=True
while changed:
    changed=False
    for idx in range(0,N,1):
        for idt in range(0,N,1):
            if bool(Kost[idx][idt]) == False:
                continue
            else:
                zen=Kost[idx][idt]
                for idy in range(0,N,1):
                    ato=Kost[idt][idy]
                    if ato == None:
                        continue
                    
                    tmpKost=zen+ato
                    if Kost[idx][idy]==None or Kost[idx][idy]>tmpKost:
                        Kost[idx][idy]=tmpKost
                        changed=True

#for gyo in Kost:
#    print(gyo)

ans=None
search([])
print(ans)


Fixed submission:
#coding=UTF-8

def search(jun):
    global ans
    global R
    global r
    global rCost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += rCost[mae][r[ba]]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])


mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono) -1 ) for mono in hyo]

michi=[]
for idx in range(0,N,1):
    michi.append([])

for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])
    michi[A].append((B,C))
    michi[B].append((A,C))


rCost=[]
for idr in range(0,R,1):
    Cost=[None]*N
    Cost[r[idr]]=0
    miru=[r[idr]]
    while miru:
        nextmiru=[]
        for toshi in miru:
            preCost=Cost[toshi]
            for (saki,sakiCost) in michi[toshi]:
                tmpCost=preCost+sakiCost
                if Cost[saki]==None or tmpCost < Cost[saki]:
                    Cost[saki]=tmpCost
                    nextmiru.append(saki)

        miru=list(set(nextmiru))
    rCost.append(Cost)

#for ko in rCost:
#    print(ko)

ans=None
search([])
print(ans)

Buggy python submission (verdict: Runtime Error):
#coding=UTF-8

def search(jun):
    global ans
    global R
    global Kost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += Kost[r[mae]][r[ba]]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])

mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono)-1) for mono in hyo]

Kost=[]
for idx in range(0,N,1):
    Kost.append([None]*N)

for idx in range(0,N,1):
    Kost[idx][idx]=0


for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])

    Kost[A][B]=C
    Kost[B][A]=C

changed=True
while changed:
    changed=False
    for idx in range(0,N,1):
        for idt in range(0,N,1):
            if bool(Kost[idx][idt]) == False:
                continue
            else:
                zen=Kost[idx][idt]
                for idy in range(0,N,1):
                    tmpKost=zen+Kost[idt][idy]
                    if Kost[idx][idy]==None or Kost[idx][idy]>tmpKost:
                        Kost[idx][idy]=tmpKost
                        changed=True

#for gyo in Kost:
#    print(gyo)

ans=None
search([])
print(ans)


Fixed submission:
#coding=UTF-8

def search(jun):
    global ans
    global R
    global r
    global rCost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += rCost[mae][r[ba]]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])


mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono) -1 ) for mono in hyo]

michi=[]
for idx in range(0,N,1):
    michi.append([])

for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])
    michi[A].append((B,C))
    michi[B].append((A,C))


rCost=[]
for idr in range(0,R,1):
    Cost=[None]*N
    Cost[r[idr]]=0
    miru=[r[idr]]
    while miru:
        nextmiru=[]
        for toshi in miru:
            preCost=Cost[toshi]
            for (saki,sakiCost) in michi[toshi]:
                tmpCost=preCost+sakiCost
                if Cost[saki]==None or tmpCost < Cost[saki]:
                    Cost[saki]=tmpCost
                    nextmiru.append(saki)

        miru=list(set(nextmiru))
    rCost.append(Cost)

#for ko in rCost:
#    print(ko)

ans=None
search([])
print(ans)