結果

問題 No.3103 Butterfly Effect
ユーザー titia
提出日時 2025-04-15 03:23:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,358 ms / 5,000 ms
コード長 1,037 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 82,904 KB
実行使用メモリ 232,628 KB
最終ジャッジ日時 2025-04-15 03:23:56
合計ジャッジ時間 36,828 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

from heapq import heappop,heappush


N,QU=map(int,input().split())
ANS=1
DIS=[1<<30]*(N+1)
DIS[1]=0
E=[[] for i in range(N+1)]

Q=[]
LANS=[]
for i in range(QU):
    p,x,y=map(int,input().split())

    heappush(E[x],(-p,y))
    heappush(E[y],(-p,x))

    if DIS[x]<p and DIS[y]<p:
        pass
    elif DIS[x]<p:
        heappush(Q,DIS[x]*1000000+x)
    if DIS[y]<p:
        heappush(Q,DIS[y]*1000000+y)

    while Q:
        qq=heappop(Q)
        now=qq//1000000
        town=qq-now*1000000

        while E[town] and now<=-E[town][0][0]:
            time,to=heappop(E[town])
            time=-time

            if now<=time:
                if DIS[to]==1<<30:
                    ANS+=1
                    DIS[to]=time
                    heappush(Q,DIS[to]*1000000+to)
                elif DIS[to]>time:
                    DIS[to]=time
                    heappush(Q,DIS[to]*1000000+to)

    LANS.append(ANS)

print("\n".join(map(str,LANS)))
    
0