問題一覧 > 通常問題

No.3669 Errors Are Absolutely Not Allowed

レベル : / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 23
作問者 : harurun / テスター : 👑 みうね TKTYI
お気に入りにしたユーザー ProblemId : 13799 / 自分の提出
問題文最終更新日: 2026-09-04 11:28:01
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 512 BONSAI (順位表) の他の問題:

Problem Statement

You are given a simple undirected connected graph with $N$ vertices and $M$ edges. The $i$-th edge connects vertex $u_i$ and vertex $v_i$, and its length is the irreducible fraction $\dfrac{a_i}{b_i}$. For each $i=2,...,N$, output the shortest distance from vertex $1$ as an irreducible fraction.

Input

The input is given from standard input in the following format.

$N\ M$
$u_1\ v_1\ a_1\ b_1$
$\vdots$
$u_M\ v_M\ a_M\ b_M$
  • $2\leq N\leq 3\times 10^4$
  • $N-1\leq M\leq \min(5\times 10^4, N(N-1)/2)$
  • $1\leq u_i, v_i\leq N$
  • $1\leq a_i, b_i\leq 300$
  • The given graph is simple and connected.
  • $\text{gcd}(a_i,b_i)=1$
  • All input values are integers.

Output

Output $N-1$ lines. On the $i$-th line, when the shortest distance to vertex $i+1$ is represented by the irreducible fraction $\dfrac{c}{d}$, output it in the following format.

$c$ $d$

Print a newline at the end.

Sample

Sample 1
Input
4 3
2 3 1 1
1 3 1 2
2 4 2 1
Output
3 2
1 2
7 2
Sample 2
Input
8 10
2 3 2 3
1 5 5 4
6 8 10 9
1 8 8 13
1 2 9 17
3 6 86 79
1 4 9 1
5 7 2 5
1 6 2 3
6 7 3 2
Output
9 17
61 51
9 1
5 4
2 3
33 20
8 13

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。