#ABC108D. All Your Paths are Different Lengths

All Your Paths are Different Lengths

题目描述

You are given an integer LL. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved that such a graph always exists.

  • The number of vertices, NN, is at most 2020. The vertices are given ID numbers from 11 to NN.
  • The number of edges, MM, is at most 6060. Each edge has an integer length between 00 and 10610^6 (inclusive).
  • Every edge is directed from the vertex with the smaller ID to the vertex with the larger ID. That is, 1,2,...,N1,2,...,N is one possible topological order of the vertices.
  • There are exactly LL different paths from Vertex 11 to Vertex NN. The lengths of these paths are all different, and they are integers between 00 and L1L-1.

Here, the length of a path is the sum of the lengths of the edges contained in that path, and two paths are considered different when the sets of the edges contained in those paths are different.

给你一个整数 LL 。请构建一个满足以下条件的有向图。该图可能包含同一对顶点之间的多条边。可以证明这样的图总是存在的。

  • 顶点数 NN 最多为 2020 。顶点的 ID 号从 11NN
  • 边的数量 MM 最多为 6060 。每条边的整数长度在 0010610^6 之间(含)。
  • 每条边都从 ID 较小的顶点指向 ID 较大的顶点。也就是说, 1,2,...,N1,2,...,N 是顶点的一种可能拓扑顺序。
  • 从顶点 11 到顶点 NN 恰好有 LL 条不同的路径。这些路径的长度各不相同,都是介于 00L1L-1 之间的整数。

这里,一条路径的长度是该路径所包含的边的长度之和,当两条路径所包含的边的集合不同时,这两条路径就被认为是不同的。

输入格式

输入内容按以下格式标准输入:

LL

输出格式

在第一行,打印 NNMM 图形中的顶点和边的数量。在接下来 MM 行的 ii /-th 中,打印三个整数 ui,viu_i,v_iwiw_i ,分别代表起始顶点、终止顶点和 ii /-th 边的长度。如果有多个解决方案,我们将接受其中任何一个。

样例 #1

样例输入 #1

4

样例输出 #1

8 10
1 2 0
2 3 0
3 4 0
1 5 0
2 6 0
3 7 0
4 8 0
5 6 1
6 7 1
7 8 1

样例 #2

样例输入 #2

5

样例输出 #2

5 7
1 2 0
2 3 1
3 4 0
4 5 0
2 4 0
1 3 3
3 5 1

说明

数据规模与约定

  • 2L1062 \leq L \leq 10^6
  • LL 是整数。

样例 11 解释

在示例输出所代表的图中,从顶点 11N=8N=8 有四条路径:

  • 1122334488 ,长度为 00
  • 1122337788 ,长度为 11
  • 1122667788 ,长度为 22
  • 1155667788 ,长度为 33

还有其他可能的解决方案。