from heapq import *
N, M, U = map(int, input().split())
roads = [tuple(reversed(list(map(int, input().split())))) for _ in range(M)]
Q = sorted(tuple(reversed(list(map(int, input().split())))) + (i,) for i in range(U))
parents = [-1]*(N+1)
out = [None]*U
heapify(roads)
for t, aq, bq, i in Q:
while len(roads) > 0 and t >= roads[0][0]:
_, a, b = heappop(roads)
V = [a]
while parents[a] != -1:
a = parents[a]
V.append(a)
while parents[b] != -1:
b = parents[b]
for e in V:
parents[e] = b
while parents[aq] != -1:
aq = parents[aq]
while parents[bq] != -1:
bq = parents[bq]
out[i] = "TAIP" if aq == bq else "NE"
print("\n".join(out))
컴파일 시 표준 출력 (stdout) 메시지
Compiling 'Main.py'...
=======
adding: __main__.pyc (deflated 35%)
=======
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |