310493: CF1842D. Tenzing and His Animal Friends

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Tenzing and His Animal Friends time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTell a story about me and my animal friends.

Tenzing has $n$ animal friends. He numbers them from $1$ to $n$.

One day Tenzing wants to play with his animal friends. To do so, Tenzing will host several games.

In one game, he will choose a set $S$ which is a subset of $\{1,2,3,...,n\}$ and choose an integer $t$. Then, he will play the game with the animals in $S$ for $t$ minutes.

But there are some restrictions:

  1. Tenzing loves friend $1$ very much, so $1$ must be an element of $S$.
  2. Tenzing doesn't like friend $n$, so $n$ must not be an element of $S$.
  3. There are m additional restrictions. The $i$-th special restriction is described by integers $u_i$, $v_i$ and $y_i$, suppose $x$ is the total time that exactly one of $u_i$ and $v_i$ is playing with Tenzing. Tenzing must ensure that $x$ is less or equal to $y_i$. Otherwise, there will be unhappiness.

Tenzing wants to know the maximum total time that he can play with his animal friends. Please find out the maximum total time that Tenzing can play with his animal friends and a way to organize the games that achieves this maximum total time, or report that he can play with his animal friends for an infinite amount of time. Also, Tenzing does not want to host so many games, so he will host at most $n^2$ games.

Input

The first line of input contains two integers $n$ and $m$ ($2 \leq n \leq 100$, $0 \leq m \leq \frac{n(n-1)}{2}$) — the number of animal friends and the number of special restrictions.

The $i$-th of the following $m$ lines of input contains three integers $u_i$, $v_i$ and $y_i$ ($1\leq u_i<v_i\leq n$, $0\leq y_i\leq 10^9$) — describing the $i$-th special restriction. It is guaranteed that for $1 \leq i < j \leq m$, $(u_i,v_i) \neq (u_j,v_j)$.

Output

If Tenzing can play with his animal friends for an infinite amount of time, output "inf". (Output without quotes.)

Otherwise, in the first line, output the total time $T$ ($0 \leq t \leq 10^{18}$) and the number of games $k$ ($0 \leq k \leq n^2$).

In the following $k$ lines of output, output a binary string $s$ of length $n$ and an integer $t$ ($0 \leq t \leq 10^{18}$) — representing the set $S$ and the number of minutes this game will be played. If $s_i=\texttt{1}$, then $i \in S$, otherwise if $s_i=\texttt{0}$, then $i \notin S$.

Under the constraints of this problem, it can be proven that if Tenzing can only play with his friends for a finite amount of time, then he can only play with them for at most $10^{18}$ minutes.

ExamplesInput
5 4
1 3 2
1 4 2
2 3 1
2 5 1
Output
4 4
10000 1
10010 1
10100 1
11110 1
Input
3 0
Output
inf
Note

In the first test case:

  1. Tenzing will host a game with friend $\{1\}$ for $1$ minute.
  2. Tenzing will host a game with friends $\{1,4\}$ for $1$ minute.
  3. Tenzing will host a game with friends $\{1,3\}$ for $1$ minute.
  4. Tenzing will host a game with friends $\{1,2,3,4\}$ for $1$ minute.

If after that, Tenzing host another game with friends $\{1,2\}$ for $1$ minute. Then the time of exactly one of friends $2$ or $3$ with Tenzing will becomes $2$ minutes which will not satisfy the $3$-rd special restriction.

In the second test case, there is no special restrictions. So Tenzing can host a game with friend $\{1\}$ for an infinite amount of time.

Input

题意翻译

Tenzing 有 $n$ 个朋友,每次举办聚会可以邀请一些朋友,有如下限制: * $1$ 必须参加,$n$ 不能参加。 * 有 $m$ 条限制 $(u, v, w)$,表示 $u$ 和 $v$ 中只有一个在聚会中的总时间不超过 $w$。 最大化聚会总时间,并给出相应方案,即给出总聚会时间,每次聚会给出参与聚会的人和单次聚会时长。

Output

**题目大意**:

丹增有 $ n $ 个动物朋友,编号从 $ 1 $ 到 $ n $。有一天,丹增想要和动物朋友们玩游戏。他会举行几轮游戏,每轮游戏选择一个集合 $ S $($ \{1,2,3,...,n\} $ 的子集)和一个整数 $ t $,然后和集合 $ S $ 中的动物玩 $ t $ 分钟。

但是有一些限制:
1. 丹增非常喜欢朋友 $ 1 $,所以 $ 1 $ 必须是集合 $ S $ 的一个元素。
2. 丹增不喜欢朋友 $ n $,所以 $ n $ 不能是集合 $ S $ 的元素。
3. 还有 $ m $ 个附加限制。第 $ i $ 个特殊限制由整数 $ u_i $, $ v_i $ 和 $ y_i $ 描述,假设 $ x $ 是恰好 $ u_i $ 和 $ v_i $ 中的一个和丹增玩的总时间。丹增必须确保 $ x $ 小于或等于 $ y_i $。否则,会有不愉快。

丹增想知道他可以和动物朋友们玩的最大总时间。请找出丹增可以和动物朋友们玩的最大总时间以及实现这一最大总时间的游戏组织方式,或者报告他可以和动物朋友们玩无限长的时间。另外,丹增不想举办太多游戏,所以他最多会举办 $ n^2 $ 轮游戏。

**输入数据格式**:

第一行输入包含两个整数 $ n $ 和 $ m $ ($ 2 \leq n \leq 100 $, $ 0 \leq m \leq \frac{n(n-1)}{2} $) —— 动物朋友的数量和特殊限制的数量。

接下来的 $ m $ 行中的每一行输入包含三个整数 $ u_i $, $ v_i $ 和 $ y_i $ ($ 1 \leq u_i < v_i \leq n $, $ 0 \leq y_i \leq 10^9 $) —— 描述第 $ i $ 个特殊限制。保证对于 $ 1 \leq i < j \leq m $,$ (u_i,v_i) \neq (u_j,v_j) $。

**输出数据格式**:

如果丹增可以和动物朋友们玩无限长的时间,输出 "inf"。(不带引号。)

否则,在第一行输出总时间 $ T $ ($ 0 \leq T \leq 10^{18} $) 和游戏数量 $ k $ ($ 0 \leq k \leq n^2 $)。

在接下来的 $ k $ 行输出中,输出一个长度为 $ n $ 的二进制字符串 $ s $ 和一个整数 $ t $ ($ 0 \leq t \leq 10^{18} $) —— 分别代表集合 $ S $ 和本轮游戏将持续的分钟数。如果 $ s_i=\texttt{1} $,那么 $ i \in S $,否则如果 $ s_i=\texttt{0} $,那么 $ i \notin S $。

根据这个问题的约束,可以证明如果丹增只能和朋友们玩有限的时间,那么他最多只能和他们玩 $ 10^{18} $ 分钟。**题目大意**: 丹增有 $ n $ 个动物朋友,编号从 $ 1 $ 到 $ n $。有一天,丹增想要和动物朋友们玩游戏。他会举行几轮游戏,每轮游戏选择一个集合 $ S $($ \{1,2,3,...,n\} $ 的子集)和一个整数 $ t $,然后和集合 $ S $ 中的动物玩 $ t $ 分钟。 但是有一些限制: 1. 丹增非常喜欢朋友 $ 1 $,所以 $ 1 $ 必须是集合 $ S $ 的一个元素。 2. 丹增不喜欢朋友 $ n $,所以 $ n $ 不能是集合 $ S $ 的元素。 3. 还有 $ m $ 个附加限制。第 $ i $ 个特殊限制由整数 $ u_i $, $ v_i $ 和 $ y_i $ 描述,假设 $ x $ 是恰好 $ u_i $ 和 $ v_i $ 中的一个和丹增玩的总时间。丹增必须确保 $ x $ 小于或等于 $ y_i $。否则,会有不愉快。 丹增想知道他可以和动物朋友们玩的最大总时间。请找出丹增可以和动物朋友们玩的最大总时间以及实现这一最大总时间的游戏组织方式,或者报告他可以和动物朋友们玩无限长的时间。另外,丹增不想举办太多游戏,所以他最多会举办 $ n^2 $ 轮游戏。 **输入数据格式**: 第一行输入包含两个整数 $ n $ 和 $ m $ ($ 2 \leq n \leq 100 $, $ 0 \leq m \leq \frac{n(n-1)}{2} $) —— 动物朋友的数量和特殊限制的数量。 接下来的 $ m $ 行中的每一行输入包含三个整数 $ u_i $, $ v_i $ 和 $ y_i $ ($ 1 \leq u_i < v_i \leq n $, $ 0 \leq y_i \leq 10^9 $) —— 描述第 $ i $ 个特殊限制。保证对于 $ 1 \leq i < j \leq m $,$ (u_i,v_i) \neq (u_j,v_j) $。 **输出数据格式**: 如果丹增可以和动物朋友们玩无限长的时间,输出 "inf"。(不带引号。) 否则,在第一行输出总时间 $ T $ ($ 0 \leq T \leq 10^{18} $) 和游戏数量 $ k $ ($ 0 \leq k \leq n^2 $)。 在接下来的 $ k $ 行输出中,输出一个长度为 $ n $ 的二进制字符串 $ s $ 和一个整数 $ t $ ($ 0 \leq t \leq 10^{18} $) —— 分别代表集合 $ S $ 和本轮游戏将持续的分钟数。如果 $ s_i=\texttt{1} $,那么 $ i \in S $,否则如果 $ s_i=\texttt{0} $,那么 $ i \notin S $。 根据这个问题的约束,可以证明如果丹增只能和朋友们玩有限的时间,那么他最多只能和他们玩 $ 10^{18} $ 分钟。

加入题单

上一题 下一题 算法标签: