Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
import sys
input = sys.stdin.readline

def main():
    INF = float("Inf")
    n,m,l = map(int, input().split())
    G = [[INF]*n for i in range(n)]
    for i in range(n):
        G[i][i] = 0
    for i in range(m):
        a,b,c = map(int, input().split())
        a,b = a-1,b-1
        if c <= l:
            G[a][b] = G[b][a] = c
    G = floyd_warshall(G, directed=False)
    G = np.where(G <=l, 1, INF)
    for i in range(n):
        G[i][i] = 0
    GG = floyd_warshall(G, directed=False)

    q = int(input())
    ans = []
    for i in range(q):
        s,t = map(int, input().split())
        a = int(GG[s-1][t-1])
        if a == INF:
            a = 0
        ans.append(a-1)
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()


Fixed submission:
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
import sys
input = sys.stdin.readline

def main():
    INF = float("Inf")
    n,m,l = map(int, input().split())
    G = [[INF]*n for i in range(n)]
    for i in range(n):
        G[i][i] = 0
    for i in range(m):
        a,b,c = map(int, input().split())
        a,b = a-1,b-1
        if c <= l:
            G[a][b] = G[b][a] = c
    G = floyd_warshall(G, directed=False)
    G = np.where(G <=l, 1, INF)
    for i in range(n):
        G[i][i] = 0
    GG = floyd_warshall(G, directed=False)

    q = int(input())
    ans = []
    for i in range(q):
        s,t = map(int, input().split())
        a = GG[s-1][t-1]
        if a == INF:
            a = 0
        else:
            a = int(a)
        ans.append(a-1)
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    INF = float("Inf")
    n,m,l = map(int, input().split())
    G = [[INF]*n for i in range(n)]
    for i in range(n):
        G[i][i] = 0
    for i in range(m):
        a,b,c = map(int, input().split())
        a,b = a-1,b-1
        if c <= l:
            G[a][b] = G[b][a] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                if G[i][k]!=INF and G[k][j]!=INF:
                    G[i][j] = min(G[i][j], G[i][k] + G[k][j])

    #最短経路がL以下の部分について、edgeをつなぐ
    GG = [[INF]*n for i in range(n)]
    for i in range(n):
        for j in range(n):
            if i == j:
                GG[i][j] = 0
            else:
                if G[i][j] <= l:
                    GG[i][j] = 1

    for k in range(n):
        for i in range(n):
            for j in range(n):
                if GG[i][k]!=INF and GG[k][j]!=INF:
                    GG[i][j] = min(GG[i][j], GG[i][k] + GG[k][j])

    q = int(input())
    ans = []
    for i in range(q):
        s,t = map(int, input().split())
        a = GG[s-1][t-1]
        if a == INF:
            a = 0
        ans.append(a-1)
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()


Fixed submission:
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
import sys
input = sys.stdin.readline

def main():
    INF = float("Inf")
    n,m,l = map(int, input().split())
    G = [[INF]*n for i in range(n)]
    for i in range(n):
        G[i][i] = 0
    for i in range(m):
        a,b,c = map(int, input().split())
        a,b = a-1,b-1
        if c <= l:
            G[a][b] = G[b][a] = c
    G = floyd_warshall(G, directed=False)
    G = np.where(G <=l, 1, INF)
    for i in range(n):
        G[i][i] = 0
    GG = floyd_warshall(G, directed=False)

    q = int(input())
    ans = []
    for i in range(q):
        s,t = map(int, input().split())
        a = GG[s-1][t-1]
        if a == INF:
            a = 0
        else:
            a = int(a)
        ans.append(a-1)
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
INF = float("Inf")
n,m,l = map(int, input().split())
G = [[INF]*n for i in range(n)]
for i in range(n):
    G[i][i] = 0
for i in range(m):
    a,b,c = map(int, input().split())
    a,b = a-1,b-1
    if c <= l:
        G[a][b] = G[b][a] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            if G[i][k]!=INF and G[k][j]!=INF:
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])

#最短経路がL以下の部分について、edgeをつなぐ
GG = [[INF]*n for i in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            GG[i][j] = 0
        else:
            if G[i][j] <= l:
                GG[i][j] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            if GG[i][k]!=INF and GG[k][j]!=INF:
                GG[i][j] = min(GG[i][j], GG[i][k] + GG[k][j])

q = int(input())
ans = []
for i in range(q):
    s,t = map(int, input().split())
    a = GG[s-1][t-1]
    if a == INF:
        a = 0
    ans.append(a-1)
print(*ans, sep="\n")

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
import sys
input = sys.stdin.readline

def main():
    INF = float("Inf")
    n,m,l = map(int, input().split())
    G = [[INF]*n for i in range(n)]
    for i in range(n):
        G[i][i] = 0
    for i in range(m):
        a,b,c = map(int, input().split())
        a,b = a-1,b-1
        if c <= l:
            G[a][b] = G[b][a] = c
    G = floyd_warshall(G, directed=False)
    G = np.where(G <=l, 1, INF)
    for i in range(n):
        G[i][i] = 0
    GG = floyd_warshall(G, directed=False)

    q = int(input())
    ans = []
    for i in range(q):
        s,t = map(int, input().split())
        a = GG[s-1][t-1]
        if a == INF:
            a = 0
        else:
            a = int(a)
        ans.append(a-1)
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n,m,l = map(int, input().split())
G = [[] for i in range(n)]
for i in range(m):
    a,b,c = map(int, input().split())
    a,b = a-1,b-1
    if c <= l:
        G[a].append((b,c))
        G[b].append((a,c))

from collections import deque

def check(s,t):
    DP1 = [-1]*n
    DP2 = [float("inf")]*n
    
    q = deque()
    q.append((s,0,l))
    while q:
        cur, cnt, rem = q.popleft()
        if DP2[cur] < cnt:
            continue
        if DP2[cur] == cnt and DP1[cur] > rem:
            continue
        DP2[cur] = cnt
        DP1[cur] = rem
        for to, c in G[cur]:
            if rem >= c:
                if DP2[to] > cnt or (DP2[to] == cnt and DP1[to]<rem-c):
                    q.appendleft((to,cnt,rem-c))
            if DP2[to] > cnt+1:
                q.append((to,cnt+1,l-c))
    ret = DP2[t]
    if ret == float("inf"):
        ret = -1
    return ret



q = int(input())
ans = []
for i in range(q):
    s,t = map(int, input().split())
    s,t = s-1, t-1
    ans.append(check(s,t))
print(*ans, sep="\n")

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
import sys
input = sys.stdin.readline

def main():
    INF = float("Inf")
    n,m,l = map(int, input().split())
    G = [[INF]*n for i in range(n)]
    for i in range(n):
        G[i][i] = 0
    for i in range(m):
        a,b,c = map(int, input().split())
        a,b = a-1,b-1
        if c <= l:
            G[a][b] = G[b][a] = c
    G = floyd_warshall(G, directed=False)
    G = np.where(G <=l, 1, INF)
    for i in range(n):
        G[i][i] = 0
    GG = floyd_warshall(G, directed=False)

    q = int(input())
    ans = []
    for i in range(q):
        s,t = map(int, input().split())
        a = GG[s-1][t-1]
        if a == INF:
            a = 0
        else:
            a = int(a)
        ans.append(a-1)
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()