Submission #1159884

#TimeUsernameProblemLanguageResultExecution timeMemory
1159884eliiasgDrivers (BOI24_drivers)Pypy 3
0 / 100
2096 ms51332 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()
        while parents[b] != -1:
            b = parents[b]
        while parents[a] != -1:
            p = a
            a = parents[a]
            parents[p] = b
        parents[a] = 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))

Compilation message (stdout)

Compiling 'Main.py'...

=======
  adding: __main__.pyc (deflated 37%)

=======
#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...