| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1283229 | dev_pandey20 | Drivers (BOI24_drivers) | Pypy 3 | 0 ms | 0 KiB |
def solve():
read N, M, U
edges = [] # list of (t, u, v)
for i in range(M):
u, v, t = map(int, input().split())
edges.append((t, u-1, v-1))
queries = []
for qi in range(U):
a, b, p = map(int, input().split())
queries.append((p, a-1, b-1, qi))
# Sort edges by weight
edges.sort(key=lambda e: e[0])
# Prepare DSU structures for thresholds 1..10
dsus = [ DSU(N) for _ in range(11) ] # index by p from 0..10 (we use 1..10)
# Alternatively, you can use one DSU and carry over, copying parent arrays
idx = 0
for thr in range(1, 11):
# inherit from previous threshold
if thr > 1:
dsus[thr].parent = dsus[thr-1].parent.copy()
dsus[thr].rank = dsus[thr-1].rank.copy()
# add edges with weight == thr
while idx < len(edges) and edges[idx][0] == thr:
_, u, v = edges[idx]
dsus[thr].union(u, v)
idx += 1
# Process queries
ans = [False] * U
for p, a, b, qi in queries:
if dsus[p].find(a) == dsus[p].find(b):
ans[qi] = True
for i in range(U):
print("TAIP" if ans[i] else "NE")
