Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 3,569 Bytes
e329daf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<p>
With a successful commission under his belt, Carlos has really made a splash
with his consulting firm, Carlos Structures Industries. His next customer is
Texas Instruments, the well-known manufacturer of graphing calculators.
</p>

<p>
<em>
"In today's competitive environment, you need an edge. I can make sure that
your newest graphing calculator is chock-full of the best modern graphs."
</em>
</p>

<p>
Carlos's pitch seems to have worked as Texas Instruments has ordered an
undirected, weighted graph. Their R&D department has come up with a list
of requirements that will ensure the graph is a hit with Gen Z schoolchildren.
</p>

<p>
To start with, the graph must have <strong>N</strong> nodes numbered 1 to <strong>N</strong>. It must have no
self-loops and at most one edge connecting each unordered pair of nodes. The
weight of each edge must be an integer between 1 and 1,000,000, inclusive.
The graph does not need to be connected.
</p>

<p>
The graph must also satisfy <strong>M</strong> customer requirements, the <em>i</em>th of which states 
that the shortest distance between two different nodes <strong>X<sub>i</sub></strong> and <strong>Y<sub>i</sub></strong> must be equal to <strong>Z<sub>i</sub></strong>. 
No two requirements pertain to the same unordered pair of nodes.
</p>

<p>
Carlos's goal is to find any valid graph consistent with all of these requirements
if possible, or to determine that no such graph exists.
</p>



<h3>Input</h3>

<p>
Input begins with an integer <strong>T</strong>, the number of graphs that Texas Instruments has commissioned.
For each graph, there is first a line containing the space-separated integers <strong>N</strong> and <strong>M</strong>.
Then, <strong>M</strong> lines follow, the <em>i</em>th of which contains the space-separated integers
<strong>X<sub>i</sub></strong>, <strong>Y<sub>i</sub></strong>, and <strong>Z<sub>i</sub></strong>.
</p>


<h3>Output</h3>

<p>
For the <em>i</em>th graph, print a line containing "Case #<em>i</em>: "
followed by either an integer <strong>E</strong> and then a description of a valid graph if possible, or the string "Impossible" if no valid graph exists. 
</p>

<p>
A graph description contains <strong>E</strong> lines, where <strong>E</strong> is the number of edges in your graph.
The <em>i</em>th line contains the space-separated integers
<strong>A<sub>i</sub></strong>, <strong>B<sub>i</sub></strong>, and <strong>W<sub>i</sub></strong>
indicating that there is an edge between nodes <strong>A<sub>i</sub></strong> and <strong>B<sub>i</sub></strong> with weight <strong>W<sub>i</sub></strong>.
Please keep in mind that your graph must satisfy all of the requirements stated above (both the fundamental requirements dictated by Texas Instruments, and the <strong>M</strong> customer ones).
</p>


<h3>Constraints</h3>

<p>
1 &le; <strong>T</strong> &le; 350 <br />
2 &le; <strong>N</strong> &le; 50 <br />
1 &le; <strong>M</strong> &le; 1,000 <br />
1 &le; <strong>X<sub>i</sub></strong>, <strong>Y<sub>i</sub></strong> &le; <strong>N</strong> <br />
<strong>X<sub>i</sub></strong> &ne; <strong>Y<sub>i</sub></strong> <br />
1 &le; <strong>Z<sub>i</sub></strong> &le; 1,000,000 <br />
</p>

<h3>Explanation of Sample</h3>

<p>
In the graph described by the first sample case's sample output, the shortest distance between nodes 3 and 1 is 5 (along the path 3 -> 2 -> 1), as required. <b>Multiple other outputs would also be accepted for this case.</b>
</p>

<p>
<b>Multiple other outputs would also be accepted for the third and fourth cases.</b>
</p>