connected
of size numCourses
x numCourses
with False
values.connected[i][j]
to True
for each direct prerequisite (i, j)
.k
, update connected[i][j]
to True
if connected[i][k]
and connected[k][j]
are True
for all pairs (i, j)
.(u, v)
, check if connected[u][v]
is True
and return the result in an answer list.