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

import numpy as np

n, m = map(int, input().split())
links = [[] for _ in range(n)]
for line in sys.stdin:
    s, t = map(int, line.split())
    s -= 1
    t -= 1
    links[s].append(t)

not_omitted = np.zeros(n, dtype=np.float64)
for j in range(n - 2, -1, -1):
    exp = not_omitted[links[j]]
    not_omitted[j] = exp.mean() + 1

ans = not_omitted[0]

for i in range(n - 1):
    expected = not_omitted.copy()

    exp = expected[links[i]]
    if exp.size == 1:
        expected[i] = exp.mean() + 1
    else:
        expected[i] = (exp.sum() - exp.max()) / (exp.size - 1) + 1

    for j in range(i - 1, -1, -1):
        exp = expected[links[j]]
        expected[j] = exp.mean() + 1

    ans = min(ans, expected[0])

print(ans)


Fixed submission:
import sys

n, m = map(int, input().split())
links = [set() for _ in range(n)]
counts = [0] * n
for line in sys.stdin:
    s, t = map(int, line.split())
    s -= 1
    t -= 1
    links[s].add(t)
    counts[s] += 1

not_omitted = [0.0] * n
exp_get = not_omitted.__getitem__
for j in range(n - 2, -1, -1):
    not_omitted[j] = sum(map(exp_get, links[j])) / counts[j] + 1

ans = 1e6

for i in range(n - 1):
    expected = [0.0] * n
    expected[i + 1:] = not_omitted[i + 1:]
    e_get = expected.__getitem__

    if counts[i] == 1:
        expected[i] = sum(map(e_get, links[i])) / counts[i] + 1
    else:
        exp = list(map(e_get, links[i]))
        expected[i] = (sum(exp) - max(exp)) / (counts[i] - 1) + 1

    for j in range(i - 1, -1, -1):
        expected[j] = sum(map(e_get, links[j])) / counts[j] + 1

    ans = min(ans, expected[0])

print(ans)

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

import numpy as np

n, m = map(int, input().split())
links = np.zeros((n, n), dtype=np.bool)
for line in sys.stdin:
    s, t = map(int, line.split())
    s -= 1
    t -= 1
    links[s][t] = True

not_omitted = np.zeros(n, dtype=np.float64)
for j in range(n - 2, -1, -1):
    exp = not_omitted[links[j]]
    not_omitted[j] = exp.sum() / exp.size + 1

ans = not_omitted[0]

for i in range(n - 1):
    expected = not_omitted.copy()

    exp = expected[links[i]]
    if exp.size == 1:
        expected[i] = exp.sum() / exp.size + 1
    else:
        expected[i] = (exp.sum() - exp.max()) / (exp.size - 1) + 1

    for j in range(i - 1, -1, -1):
        exp = expected[links[j]]
        expected[j] = exp.sum() / exp.size + 1

    ans = min(ans, expected[0])

print(ans)


Fixed submission:
import sys

n, m = map(int, input().split())
links = [set() for _ in range(n)]
counts = [0] * n
for line in sys.stdin:
    s, t = map(int, line.split())
    s -= 1
    t -= 1
    links[s].add(t)
    counts[s] += 1

not_omitted = [0.0] * n
exp_get = not_omitted.__getitem__
for j in range(n - 2, -1, -1):
    not_omitted[j] = sum(map(exp_get, links[j])) / counts[j] + 1

ans = 1e6

for i in range(n - 1):
    expected = [0.0] * n
    expected[i + 1:] = not_omitted[i + 1:]
    e_get = expected.__getitem__

    if counts[i] == 1:
        expected[i] = sum(map(e_get, links[i])) / counts[i] + 1
    else:
        exp = list(map(e_get, links[i]))
        expected[i] = (sum(exp) - max(exp)) / (counts[i] - 1) + 1

    for j in range(i - 1, -1, -1):
        expected[j] = sum(map(e_get, links[j])) / counts[j] + 1

    ans = min(ans, expected[0])

print(ans)

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

n, m = map(int, input().split())
links = [set() for _ in range(n)]
for line in sys.stdin:
    s, t = map(int, line.split())
    s -= 1
    t -= 1
    links[s].add(t)

not_omitted = [0.0] * n
exp_get = not_omitted.__getitem__
for j in range(n - 2, -1, -1):
    next_e = tuple(map(exp_get, links[j]))
    not_omitted[j] = sum(next_e) / len(next_e) + 1

ans = 1e6

for i in range(n - 1):
    expected = [0.0] * (i + 1) + not_omitted[i + 1:]
    e_get = expected.__getitem__

    next_e = tuple(map(e_get, links[i]))
    if len(next_e) == 1:
        expected[i] = sum(next_e) / len(next_e) + 1
    else:
        expected[i] = (sum(next_e) - max(next_e)) / (len(next_e) - 1) + 1

    for j in range(i - 1, -1, -1):
        next_e = tuple(map(e_get, links[j]))
        expected[j] = sum(next_e) / len(next_e) + 1

    ans = min(ans, expected[0])

print(ans)


Fixed submission:
import sys

n, m = map(int, input().split())
links = [set() for _ in range(n)]
counts = [0] * n
for line in sys.stdin:
    s, t = map(int, line.split())
    s -= 1
    t -= 1
    links[s].add(t)
    counts[s] += 1

not_omitted = [0.0] * n
exp_get = not_omitted.__getitem__
for j in range(n - 2, -1, -1):
    not_omitted[j] = sum(map(exp_get, links[j])) / counts[j] + 1

ans = 1e6

for i in range(n - 1):
    expected = [0.0] * n
    expected[i + 1:] = not_omitted[i + 1:]
    e_get = expected.__getitem__

    if counts[i] == 1:
        expected[i] = sum(map(e_get, links[i])) / counts[i] + 1
    else:
        exp = list(map(e_get, links[i]))
        expected[i] = (sum(exp) - max(exp)) / (counts[i] - 1) + 1

    for j in range(i - 1, -1, -1):
        expected[j] = sum(map(e_get, links[j])) / counts[j] + 1

    ans = min(ans, expected[0])

print(ans)

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

n, m = map(int, input().split())
links = [set() for _ in range(n)]
for line in sys.stdin:
    s, t = map(int, line.split())
    s -= 1
    t -= 1
    links[s].add(t)

not_omitted = [0.0] * n
exp_get = not_omitted.__getitem__
for j in range(n - 2, -1, -1):
    next_e = tuple(map(exp_get, links[j]))
    not_omitted[j] = sum(next_e) / len(next_e) + 1

ans = 1e6

for i in range(n - 1):
    expected = [0.0] * (i + 1) + not_omitted[i + 1:]
    e_get = expected.__getitem__

    next_e = tuple(map(e_get, links[i]))
    if len(next_e) == 1:
        expected[i] = sum(next_e) / len(next_e) + 1
    else:
        expected[i] = (sum(next_e) - max(next_e)) / (len(next_e) - 1) + 1

    for j in range(i - 1, -1, -1):
        next_e = tuple(map(e_get, links[j]))
        expected[j] = sum(next_e) / len(next_e) + 1

    ans = min(ans, expected[0])

print(ans)


Fixed submission:
import sys

n, m = map(int, input().split())
links = [set() for _ in range(n)]
counts = [0] * n
for line in sys.stdin:
    s, t = map(int, line.split())
    s -= 1
    t -= 1
    links[s].add(t)
    counts[s] += 1

not_omitted = [0.0] * n
exp_get = not_omitted.__getitem__
for j in range(n - 2, -1, -1):
    not_omitted[j] = sum(map(exp_get, links[j])) / counts[j] + 1

ans = 1e6

for i in range(n - 1):
    expected = [0.0] * n
    expected[i + 1:] = not_omitted[i + 1:]
    e_get = expected.__getitem__

    if counts[i] == 1:
        expected[i] = sum(map(e_get, links[i])) / counts[i] + 1
    else:
        exp = list(map(e_get, links[i]))
        expected[i] = (sum(exp) - max(exp)) / (counts[i] - 1) + 1

    for j in range(i - 1, -1, -1):
        expected[j] = sum(map(e_get, links[j])) / counts[j] + 1

    ans = min(ans, expected[0])

print(ans)