Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 2,937 Bytes
718fd53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<p>
The kingdom of Hackadia has <strong>N</strong> cities that are connected by <strong>M</strong> bidirectional roads. Cities are enumerated from <strong>0</strong> to <strong>N - 1</strong>. To attract tourists, the government has decided to open up some restaurant chains throughout the kingdom. Each restaurant chain will serve some subset of cities, and will have exactly one restaurant in each city of the chosen subset. Thus, each city will have some restaurant chains, and it is possible to have all possible restaurant chains in some city or not to have any restaurant chains in some city.
</p>

<p>
To ensure that tourists do not face a drastic change in the food scenario when traveling from one city to another, the government has decided that the following condition must be satisfied for each pair of cities (<strong>u</strong>, <strong>v</strong>) :
</p>

<p>
<i>
"the number of restaurant chains open in city <strong>u</strong> but not in city <strong>v</strong>" plus "the number of restaurant chains open in city <strong>v</strong> but not in city <strong>u</strong>" should always be equal to the shortest distance between city <strong>u</strong> and city <strong>v</strong>.
</i>
</p>

<p>
It is guaranteed that every two cities are connected by some sequence of bidirectional roads, and the shortest distance between city <strong>u</strong> and city <strong>v</strong> is the number of roads on the shortest path connecting <strong>u</strong> and <strong>v</strong>.
</p>

</p>
Your job is to help the government determine the minimal number of restaurant chains, such that there exist some assignment of the restaurant chains among the cities that satisfy the above condition. If such assignment is not possible print <strong>-1</strong>.
</p>

<h3>Input</h3>
<p>
The first line of the input will be the number of test cases <strong>T</strong>.
<br />
Each of the test cases start with a line containing the numbers <strong>N</strong> and <strong>M</strong>, representing the number of cities and the number of roads respectively. <br />
The next <strong>M</strong> lines of each testcase contain a pairs of integers, representing the cities connected by a bidirectional road in Hackadia. <br />
Each testcase will be followed by an empty line. <br />
</p>

<h3>Output</h3>
<p>
For each test case <strong>i</strong> numbered from 1 to <strong>T</strong>, output "Case #<strong>i</strong>: ", followed by the minimal number of restaurant chains or <strong>-1</strong>.
</p>


<h3>Constraints</h3>
<p>
1 &le; <strong>T </strong>&le; 20 <br />
1 &le; <strong>N</strong> &le; 10,000 <br />
1 &le; <strong>M</strong> &le; 50,000 <br />
</p>

<h3>Explanation</h3>
<p>
In the first example, we can have two restaurant chains (named X and Y) and have chain X serve cities 1 and 2, and have chain Y serve cities 2 and 3. <br />
In the second example, it is not possible to have such restaurant chain assignment. <br />
</p>