#K85932. Categorize Products

    ID: 36751 Type: Default 1000ms 256MiB

Categorize Products

Categorize Products

You are given three integers \(n\), \(c\), and \(m\) where \(n\) is the number of products, \(c\) is the number of categories, and \(m\) is the number of assignments between products and categories. Each of the following \(m\) lines contains two integers: a product id and a category id.

Your task is to organize these assignments and for each category from 1 to \(c\), output a line in the format: Category i: followed by the product ids assigned to that category in ascending order, each separated by a single space. If a category has no assigned products, simply output Category i: with nothing following it.

inputFormat

The input is read from standard input (stdin). The first line contains three integers (n), (c), and (m). Each of the next (m) lines contains two integers (p) and (k), where (p) is a product id and (k) is the category id.

outputFormat

Print (c) lines to standard output (stdout). The (i)-th line (1-indexed) should start with "Category i:". If there are any products assigned to category (i), print a space-separated list of product ids (sorted in ascending order) immediately after the colon. Otherwise, print nothing after the colon.## sample

5 3 4
1 2
2 1
3 2
5 1
Category 1: 2 5

Category 2: 1 3 Category 3:

</p>