QOJ.ac

QOJ

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

#20131. 拿一个图

Statistics

Bash 和 Chikapu 非常沉迷于……图。他们玩图玩得太开心,经常连饭都忘了吃。今天他们要去超市。不过,他们拿的不是零食,而是一些图。

Bash 只喜欢顶点数和边数较少的带权无向图。更准确地说,Bash 只喜欢顶点数不超过 $72$、边数不超过 $2525$ 的带权无向图。

Chikapu 只喜欢边更少的带权无向图。更准确地说,Chikapu 只喜欢顶点数不超过 $88$、边数不超过 $214$ 的带权无向图。

Bash 和 Chikapu 给超市老板 Mr. Graph Maker 一个介于 $0$ 和 $10^{18}$ 之间(含两端)的整数 $A$。他们要求他给出两个图,每个图中从顶点 $1$ 到顶点 $2$ 的最短路径数量都恰好为 $A$。(每个图必须至少有两个顶点,顶点从 $1$ 开始编号。)为了让 Mr. Graph Maker 多一点挑战,两个图都不能有自环或重边。当然,第一个图必须满足 Bash 的偏好,第二个图必须满足 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$ 的权值最小的路径。

两条路径不同,当且仅当它们的边序列不同。

输入格式

输入最多包含 $101$ 行。除了最后一行外,每行包含一个整数 $A$($0\le A\le10^{18}$),表示一组测试数据。最后一行包含数字 $-1$,不是一组测试数据。

输出格式

对于每组测试数据:

  • 如果无法构造 Bash 要求的图,输出一行,仅包含单词 NO。

  • 否则,输出一行,包含单词 YES。下一行输出两个整数 $N,M$($2\le N\le72$,$0\le M\le2525$),分别表示 Bash 的图的顶点数和边数。接下来 $M$ 行,每行输出三个整数 $u,v,c$,表示一条连接顶点 $u$ 和 $v$、权值为 $c$ 的边。($1\le u,v\le N$,$1\le c\le10^9$。)

  • 如果无法构造 Chikapu 要求的图,输出一行,仅包含单词 NO。

  • 否则,输出一行,包含单词 YES。下一行输出两个整数 $N,M$($2\le N\le88$,$0\le M\le214$),分别表示 Chikapu 的图的顶点数和边数。接下来 $M$ 行,每行输出三个整数 $u,v,c$,表示一条连接顶点 $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.