QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#20131. グラフをつかめ

Statistics

Bash と Chikapu は……グラフにひどく夢中である。グラフで遊ぶのがあまりにも楽しく、しばしば食事を抜いてしまう。今日はスーパーマーケットへ行く。しかし、お菓子を手に取る代わりに、いくつかのグラフを手に取る。

Bash は頂点数と辺数の少ない重み付き無向グラフだけが好きである。正確には、頂点が高々 $72$ 個、辺が高々 $2525$ 本の重み付き無向グラフだけが好きである。

Chikapu はさらに辺の少ない重み付き無向グラフだけが好きである。正確には、頂点が高々 $88$ 個、辺が高々 $214$ 本の重み付き無向グラフだけが好きである。

Bash と Chikapu はスーパーマーケットの店主 Mr. Graph Maker に、$0$ 以上 $10^{18}$ 以下の整数 $A$ を渡す。各グラフで、頂点 $1$ から頂点 $2$ への最短経路の個数がちょうど $A$ となる2つのグラフを求める。(各グラフには少なくとも2頂点が必要で、頂点番号は $1$ から始まる。)Mr. Graph Maker にもう少し難しい挑戦をしてもらうため、両グラフは自己ループや多重辺を含んではならない。もちろん、第1のグラフは Bash の好みを、第2のグラフは Chikapu の好みを満たさなければならない。頂点数と辺数についての好みは上述のとおりである。

Mr. Graph Maker がこれらのグラフを作るのを手伝ってほしい。

注記

グラフ $G=(V,E)$ に対し、頂点 $u$ から頂点 $v$ への経路を、次を満たす辺の列 $(a_0,a_1),(a_1,a_2),\ldots,(a_{k-1},a_k)$ と定義する:

  • $a_0=u$。

  • $a_k=v$。

  • $(a_{i-1},a_i)\in E$。

経路の重みは、その経路上のすべての辺の重みの合計である。

$u$ から $v$ への最短経路とは、$u$ から $v$ への経路のうち重みが最小のものである。

2つの経路は、その辺の列が異なるとき、かつそのときに限り異なるとする。

入力

入力は高々 $101$ 行からなる。最後の行以外の各行は、テストケースを表す整数 $A$($0\le A\le10^{18}$)を含む。最後の行は数 $-1$ を含み、テストケースではない。

出力

各テストケースについて:

  • Bash が求めるグラフを作れない場合は、単語 NO を含む1行を出力せよ。

  • そうでなければ、単語 YES を含む行を出力せよ。次の行に、Bash のグラフの頂点数と辺数を表す2つの整数 $N,M$($2\le N\le72$、$0\le M\le2525$)を出力せよ。続く $M$ 行それぞれに、頂点 $u,v$ を結ぶ重み $c$ の辺を表す3つの整数 $u,v,c$ を出力せよ。($1\le u,v\le N$、$1\le c\le10^9$。)

  • Chikapu が求めるグラフを作れない場合は、単語 NO を含む1行を出力せよ。

  • そうでなければ、単語 YES を含む行を出力せよ。次の行に、Chikapu のグラフの頂点数と辺数を表す2つの整数 $N,M$($2\le N\le88$、$0\le M\le214$)を出力せよ。続く $M$ 行それぞれに、頂点 $u,v$ を結ぶ重み $c$ の辺を表す3つの整数 $u,v,c$ を出力せよ。($1\le u,v\le N$、$1\le c\le10^9$。)

グラフは自己ループや多重辺を含んではならず、$1$ から $2$ への最短経路の個数は $A$ に等しくなければならない。

入出力例

入力 1

1
3
-1

出力 1

YES
2 1
1 2 100
YES
3 2
1 3 1000
3 2 10000
YES
5 6
1 3 1
3 2 1
1 4 1
4 2 1
1 5 1
5 2 1
YES
5 6
1 3 1
3 2 1
1 4 1
4 2 1
1 5 1
5 2 1

注記

例1で Bash に与えられたグラフ:

problem_20131_2a464600353e809580037ed168959efc.png

例1で Chikapu に与えられたグラフ:

problem_20131_f6e3cb98dbf044c126f380b5f729c05e.png

例2で Bash と Chikapu の両方に与えられたグラフ:

problem_20131_0805ccd09319460d91b39f081a44bd08.png

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.