제출 #1159880

#제출 시각아이디문제언어결과실행 시간메모리
1159880eliiasgDrivers (BOI24_drivers)Pypy 3
0 / 100
2112 ms763528 KiB
from heapq import *
N, M, U = map(int, input().split())
roads = sorted(tuple(reversed(list(map(int, input().split())))) for _ in range(M))[::-1]
Q = sorted(tuple(reversed(list(map(int, input().split())))) + (i,) for i in range(U))

parents = [-1]*(N+1)
out = [None]*U


for t, aq, bq, i in Q:
    while len(roads) > 0 and t >= roads[-1][0]:
        _, a, b = roads.pop()
        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 36%)

=======
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...