結果
問題 |
No.3103 Butterfly Effect
|
ユーザー |
![]() |
提出日時 | 2025-02-12 02:00:59 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 888 bytes |
コンパイル時間 | 331 ms |
コンパイル使用メモリ | 82,908 KB |
実行使用メモリ | 68,276 KB |
最終ジャッジ日時 | 2025-02-12 02:01:06 |
合計ジャッジ時間 | 6,134 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 1 |
other | RE * 40 |
ソースコード
import heapq from sortedcontainers import SortedSet n, q = map(int,input().split()) x = [-1] * q y = [-1] * q dp = [q+1] * n dp[0] = -1 horyu = [SortedSet() for i in range(n)] ans = 1 for num in range(q): p, x, y = map(int,input().split()) p -= 1 x -= 1 y -= 1 if dp[x] < p and dp[y] < p: pass elif dp[x] > p and dp[y] > p: horyu[x].add((p,y)) horyu[x].add((p,x)) else: if dp[y] < p: x, y = y, x assert dp[x] < p and dp[y] > p if dp[y] == q+1: ans += 1 dp[y] = p mada = [] heapq.heappush(mada, (-p, y)) while mada: t, i = heapq.heappop(mada) t = -t while True: itr = horyu[i].bisect_left((t, 0)) if itr == len(horyu[i]): break tim = horyu[i][itr][0] z = horyu[i][itr][1] horyu[i].discard(horyu[i][itr]) if dp[z] > tim: if dp[z] == q+1: ans += 1 dp[z] = tim heapq.heappush((-tim, z)) print(ans)