200892: [AtCoder]ARC089 E - GraphXY

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

Description

Score : $900$ points

Problem Statement

AtCoDeer the deer wants a directed graph that satisfies the following conditions:

  • The number of vertices, $N$, is at most $300$.
  • There must not be self-loops or multiple edges.
  • The vertices are numbered from $1$ through $N$.
  • Each edge has either an integer weight between $0$ and $100$ (inclusive), or a label X or Y.
  • For every pair of two integers $(x,y)$ such that $1 ≤ x ≤ A$, $1 ≤ y ≤ B$, the shortest distance from Vertex $S$ to Vertex $T$ in the graph where the edges labeled X have the weight $x$ and the edges labeled Y have the weight $y$, is $d_{x,y}$.

Construct such a graph (and a pair of $S$ and $T$) for him, or report that it does not exist. Refer to Output section for output format.

Constraints

  • $1$ $≤$ $A,B$ $≤$ $10$
  • $1$ $≤$ $d_{x,y}$ $≤$ $100$ ($1$ $≤$ $x$ $≤$ $A$, $1$ $≤$ $y$ $≤$ $B$)
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

$A$ $B$
$d_{1,1}$ $d_{1,2}$ $..$ $d_{1,B}$
$d_{2,1}$ $d_{2,2}$ $..$ $d_{2,B}$
$:$
$d_{A,1}$ $d_{A,2}$ $..$ $d_{A,B}$

Output

If no graph satisfies the condition, print Impossible.

If there exists a graph that satisfies the condition, print Possible in the first line. Then, in the subsequent lines, print the constructed graph in the following format:

$N$ $M$
$u_1$ $v_1$ $c_1$
$u_2$ $v_2$ $c_2$
:
$u_M$ $v_M$ $c_M$
$S$ $T$

Here, $M$ is the number of the edges, and $u_i$, $v_i$, $c_i$ represent edges as follows: there is an edge from Vertex $u_i$ to Vertex $v_i$ whose weight or label is $c_i$.

Also refer to Sample Outputs.


Sample Input 1

2 3
1 2 2
1 2 3

Sample Output 1

Possible
3 4
1 2 X
2 3 1
3 2 Y
1 3 Y
1 3

Sample Input 2

1 3
100 50 1

Sample Output 2

Impossible

Input

题意翻译

### 题目描述 给出一个$A \times B$的矩阵,其中第$i$行第$j$列元素为$d_{i,j}$。试构造一个有向图,满足: 1、有向图点数$\leq 300$; 2、图中没有自环和重边; 3、图中边有边权,边权为 $[0,100]$ 中的整数,或者是未知数`X`或`Y`; 4、对于所有$x \in [1,A] , y \in[1,B]$,满足当未知数$X = x$,$Y = y$时,图中$S$到$T$的最短路为$d_{x,y}$。 ### 输入格式 第一行两个正整数$A,B(1 \leq A , B \leq 10)$ 接下来一个$A \times B$的矩阵描述$d$。保证对于$\forall i \in [1,A] , j \in [1,B] , d_{i,j} \in [1,100]$ ### 输出格式 如果不存在满足条件的有向图,输出一行`Impossible` 否则第一行输出`Possible`,第二行输出有向图的点数$n$和边数$m$,接下来$m$行每行输出$u,v,x$描述一条从$u$到$v$、边权为$x$的有向边,最后一行两个正整数$S,T$。

加入题单

上一题 下一题 算法标签: