結果

問題 No.3669 误差绝不允许
コンテスト
ユーザー titia
提出日時 2026-09-04 23:46:24
言語 PyPy3
(7.3.23)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 424 ms / 3,000 ms
+ 111µs
コード長 665 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 227 ms
コンパイル使用メモリ 95,936 KB
実行使用メモリ 106,048 KB
最終ジャッジ日時 2026-09-04 23:46:35
合計ジャッジ時間 10,657 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

from math import gcd,lcm

from heapq import heappop,heappush

LCM=1

for i in range(1,301):
    LCM=lcm(LCM,i)

N,M=list(map(int,input().split()))

E=[[] for i in range(N)]

for i in range(M):
    x,y,a,b=list(map(int,input().split()))
    x-=1
    y-=1
    c=a*LCM//b

    E[x].append((y,c))
    E[y].append((x,c))

DIS=[LCM<<100]*N
DIS[0]=0

Q=[(0,0)]

while Q:
    dis,ind=heappop(Q)

    if DIS[ind]!=dis:
        continue

    for to,c in E[ind]:
        if DIS[to]>dis+c:
            DIS[to]=dis+c
            heappush(Q,(DIS[to],to))

for i in range(1,N):
    x=DIS[i]
    y=LCM

    G=gcd(x,y)

    print(x//G,y//G)


0