import sys
import numpy as np

from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m, l = map(int, readline().split())
rest = np.array(read().split(), np.int64)
abc = rest[: m + m + m]
a = abc[::3]
b = abc[1::3]
c = abc[2::3]
st = rest[m + m + m + 1 :]
s = st[::2]
t = st[1::2]


dist_graph = csr_matrix((c, (a, b)), (n + 1, n + 1))
dist_path = floyd_warshall(dist_graph, directed=False)

cost_graph = np.full((n + 1, n + 1), np.inf)
np.fill_diagonal(cost_graph, 0)
cost_graph[dist_path <= l] = 1

cost_path = floyd_warshall(cost_graph, directed=False)

cost_path[cost_path == np.inf] = 0
cost_path = (cost_path).astype(int)

x = cost_path[s, t] - 1

print("\n".join(x.astype(str))) import sys sys import numpy as np numpy from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines n, m, l = map(int, readline().split()) n map(int, readline().split()) map int readline().split() ().split () readline split m l rest = np.array(read().split(), np.int64) rest np.array(read().split(), np.int64) np.array np array read().split() ().split () read split np.int64 np int64 abc = rest[: m + m + m] abc rest[: m + m + m] rest : m + m + m m + m + m m + m m m m a = abc[::3] a abc[::3] abc ::3 3 b = abc[1::3] b abc[1::3] abc 1::3 1 3 c = abc[2::3] c abc[2::3] abc 2::3 2 3 st = rest[m + m + m + 1 :] st rest[m + m + m + 1 :] rest m + m + m + 1 : m + m + m + 1 m + m + m m + m m m m 1 s = st[::2] s st[::2] st ::2 2 t = st[1::2] t st[1::2] st 1::2 1 2 dist_graph = csr_matrix((c, (a, b)), (n + 1, n + 1)) dist_graph csr_matrix((c, (a, b)), (n + 1, n + 1)) csr_matrix (c, (a, b)) c (a, b) a b (n + 1, n + 1) n + 1 n 1 n + 1 n 1 dist_path = floyd_warshall(dist_graph, directed=False) dist_path floyd_warshall(dist_graph, directed=False) floyd_warshall dist_graph directed=False directed False cost_graph = np.full((n + 1, n + 1), np.inf) cost_graph np.full((n + 1, n + 1), np.inf) np.full np full (n + 1, n + 1) n + 1 n 1 n + 1 n 1 np.inf np inf np.fill_diagonal(cost_graph, 0) np.fill_diagonal np fill_diagonal cost_graph 0 cost_graph[dist_path <= l] = 1 cost_graph[dist_path <= l] cost_graph dist_path <= l dist_path l 1 cost_path = floyd_warshall(cost_graph, directed=False) cost_path floyd_warshall(cost_graph, directed=False) floyd_warshall cost_graph directed=False directed False cost_path[cost_path == np.inf] = 0 cost_path[cost_path == np.inf] cost_path cost_path == np.inf cost_path np.inf np inf 0 cost_path = (cost_path).astype(int) cost_path (cost_path).astype(int) cost_path).astype cost_path astype int x = cost_path[s, t] - 1 x cost_path[s, t] - 1 cost_path[s, t] cost_path s 1 print("\n".join(x.astype(str))) print "\n".join(x.astype(str)) "\n".join "\n" join x.astype(str) x.astype x astype str x = cost_path[s, t] - 1 cost_path[s, t] - 1 x l = map(int, readline().split()) map(int, readline().split()) l cost_path = (cost_path).astype(int) (cost_path).astype(int) cost_path read = sys.stdin.buffer.read sys.stdin.buffer.read read cost_graph = np.full((n + 1, n + 1), np.inf) np.full((n + 1, n + 1), np.inf) cost_graph cost_path = floyd_warshall(cost_graph, directed=False) floyd_warshall(cost_graph, directed=False) cost_path readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline rest = np.array(read().split(), np.int64) np.array(read().split(), np.int64) rest s = st[::2] st[::2] s m, l = map(int, readline().split()) map(int, readline().split()) m st = rest[m + m + m + 1 :] rest[m + m + m + 1 :] st abc = rest[: m + m + m] rest[: m + m + m] abc a = abc[::3] abc[::3] a dist_graph = csr_matrix((c, (a, b)), (n + 1, n + 1)) csr_matrix((c, (a, b)), (n + 1, n + 1)) dist_graph n, m, l = map(int, readline().split()) map(int, readline().split()) n c = abc[2::3] abc[2::3] c t = st[1::2] st[1::2] t b = abc[1::3] abc[1::3] b readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines dist_path = floyd_warshall(dist_graph, directed=False) floyd_warshall(dist_graph, directed=False) dist_path
import sys
import numpy as np

from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m, l = map(int, readline().split())
rest = np.array(read().split(), np.int64)
abc = rest[: m + m + m]
a = abc[::3]
b = abc[1::3]
c = abc[2::3]
st = rest[m + m + m + 1 :]
s = st[::2]
t = st[1::2]


dist_graph = csr_matrix((c, (a, b)), (n + 1, n + 1))
dist_path = floyd_warshall(dist_graph, directed=False)

cost_graph = np.full((n + 1, n + 1), np.inf)
np.fill_diagonal(cost_graph, 0)
cost_graph[dist_path <= l] = 1

cost_path = floyd_warshall(cost_graph, directed=False)

cost_path[cost_path == np.inf] = 0
cost_path = (cost_path).astype(int)

x = cost_path[s, t] - 1

print("\n".join(x.astype(str)))
