ChatDOJ, Inc. has been increasing the amount of training data exponentially to build better language models. However, it was recently discovered that data of excessively low quality can actually harm model performance.
Training and evaluating a model takes a great deal of time and money, so ChatDOJ, Inc. has devised a quality metric to evaluate the data to be used in advance.
ChatDOJ, Inc. has obtained training data items, numbered through . There are possible original sources. Item has source number and review score . Multiple items may come from the same source.
Since the data items differ in content and format, an arbitrary collection cannot necessarily be used together for training. There are given relationships indicating that two items can be used together for training.
A nonempty selection of items can be used for training only if the selected items are connected through these relationships. That is, any two selected items must be reachable from each other by passing through selected items only. Selecting just one item is also allowed.
The quality metric defined by ChatDOJ, Inc. is the product of the following two values.
Selecting multiple items from the same source counts that source only once. Adding an item with a low review score to increase the number of sources may instead decrease the quality metric.
Find the maximum quality metric that ChatDOJ, Inc. can obtain by selecting training data items.
The first line contains the number of training data items , the number of relationships , and the number of possible original sources , separated by spaces.
The next lines describe the items. The -th of these lines contains the source number and review score of item , separated by a space.
Print the maximum achievable quality metric as an integer.
In the first example, selecting items gives a connected selection with distinct original sources and a minimum review score of . The quality metric is therefore . Selecting only items gives the same value.
The next lines describe the relationships. Each line contains two item numbers and , separated by a space. The relationships are undirected.
Selecting only items is not allowed, since they cannot reach each other through selected items only. Selecting all four items increases the number of sources to , but lowers the minimum review score to , so the quality metric becomes .
In the second example, selecting items gives a quality metric of . Selecting item alone gives a quality metric of , so the answer is .
In the third example, selecting all items gives distinct original sources and a minimum review score of , so the quality metric is .