Buggy python submission (verdict: Time Limit Exceeded):
import sys
import copy

def main():
	input = sys.stdin.readline

	N, M = list(map(int,input().split()))
	st = [list(map(int,input().split())) for i in range(M)]

	neighbor = [[] for i in range(N)]
	ineighbor_init = [[] for i in range(N)]
	for s,t in st:
		neighbor[s-1].append(t-1)
		ineighbor_init[t-1].append(s-1)

	INF = 100100100
	ev = [INF]*N
	ev[N-1] = 0
	for i in range(N-2,-1,-1):
		dsum = 0
		dcount = 0
		for j in neighbor[i]:
			dsum += ev[j]
			dcount += 1
		ev[i] = dsum/dcount + 1

	ans = ev[0]
	for i in range(N-1):
		evmax = -1
		if len(neighbor[i])==1: continue
		for j in neighbor[i]:
			if ev[j]>evmax:
				tn = j
				evmax = ev[j]

		ntmp = copy.deepcopy(neighbor)
		ntmp[i].remove(tn)
		evtmp = [INF]*N
		evtmp[N-1] = 0
		for ii in range(N-2,-1,-1):
			dsum = 0
			dcount = 0
			for jj in ntmp[ii]:
				dsum += evtmp[jj]
				dcount += 1
			evtmp[ii] = dsum/dcount + 1

		if evtmp[0]<ans:
			ans = evtmp[0]

	print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
import copy

def main():
	input = sys.stdin.readline

	N, M = list(map(int,input().split()))
	st = [list(map(int,input().split())) for i in range(M)]

	neighbor = [[] for i in range(N)]
	for s,t in st:
		neighbor[s-1].append(t-1)

	INF = 100100100
	ev = [INF]*N
	ev[N-1] = 0
	for i in range(N-2,-1,-1):
		dsum = 0
		dcount = 0
		for j in neighbor[i]:
			dsum += ev[j]
			dcount += 1
		ev[i] = dsum/dcount + 1

	ans = ev[0]
	for i in range(N-1):
		evmax = -1
		if len(neighbor[i])==1: continue
		for j in neighbor[i]:
			if ev[j]>evmax:
				tn = j
				evmax = ev[j]

		# ntmp = copy.deepcopy(neighbor)
		# ntmp[i].remove(tn)
		evtmp = [INF]*N
		evtmp[i+1::] = ev[i+1::]
		for ii in range(i,-1,-1):
			dsum = 0
			dcount = 0
			for jj in neighbor[ii]:
				if ii==i and jj==tn: continue
				dsum += evtmp[jj]
				dcount += 1
			evtmp[ii] = dsum/dcount + 1

		if evtmp[0]<ans:
			ans = evtmp[0]

	print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import copy

input = sys.stdin.readline

N, M = list(map(int,input().split()))
st = [list(map(int,input().split())) for i in range(M)]

neighbor = [[] for i in range(N)]
ineighbor_init = [[] for i in range(N)]
for s,t in st:
	neighbor[s-1].append(t-1)
	ineighbor_init[t-1].append(s-1)

INF = 100100100
ev = [INF]*N
ev[N-1] = 0
for i in range(N-2,-1,-1):
	dlist = []
	for j in neighbor[i]:
		dlist.append(ev[j])
	ev[i] = sum(dlist)/len(dlist) + 1

ans = ev[0]
for i in range(N-1):
	evmax = -1
	if len(neighbor[i])==1: continue
	for j in neighbor[i]:
		if ev[j]>evmax:
			tn = j
			evmax = ev[j]

	ntmp = copy.deepcopy(neighbor)
	ntmp[i].remove(tn)
	evtmp = [INF]*N
	evtmp[N-1] = 0
	for ii in range(N-2,-1,-1):
		dlist = []
		for jj in ntmp[ii]:
			dlist.append(evtmp[jj])
		evtmp[ii] = sum(dlist)/len(dlist) + 1

	if evtmp[0]<ans:
		ans = evtmp[0]

print(ans)

Fixed submission:
import sys
import copy

def main():
	input = sys.stdin.readline

	N, M = list(map(int,input().split()))
	st = [list(map(int,input().split())) for i in range(M)]

	neighbor = [[] for i in range(N)]
	for s,t in st:
		neighbor[s-1].append(t-1)

	INF = 100100100
	ev = [INF]*N
	ev[N-1] = 0
	for i in range(N-2,-1,-1):
		dsum = 0
		dcount = 0
		for j in neighbor[i]:
			dsum += ev[j]
			dcount += 1
		ev[i] = dsum/dcount + 1

	ans = ev[0]
	for i in range(N-1):
		evmax = -1
		if len(neighbor[i])==1: continue
		for j in neighbor[i]:
			if ev[j]>evmax:
				tn = j
				evmax = ev[j]

		# ntmp = copy.deepcopy(neighbor)
		# ntmp[i].remove(tn)
		evtmp = [INF]*N
		evtmp[i+1::] = ev[i+1::]
		for ii in range(i,-1,-1):
			dsum = 0
			dcount = 0
			for jj in neighbor[ii]:
				if ii==i and jj==tn: continue
				dsum += evtmp[jj]
				dcount += 1
			evtmp[ii] = dsum/dcount + 1

		if evtmp[0]<ans:
			ans = evtmp[0]

	print(ans)

if __name__ == '__main__':
    main()