544 - 競程 CPE 班 (2013/11/28) Scoreboard

Time

2013/11/28 19:05:00 2013/11/28 22:05:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
9018 Tree
9029 All combinations

9018 - Tree   

Description

Given the relationship of the nodes in a tree, construct the tree and output it in the pre-order.  Each node has unique integer identification (ID), but all IDs may not be consecutive.

Input

There are multiple test cases.  Each test case begins with an integer N (1 <= N <=1000), denoting the number of relations in the tree.  In the following N lines, each line contains two integers a and b (1 <= a,b <= 1000), which means node a is node b’s parent.   After that, the next line contains an integer R, which represents the root of the tree.  You can assume that all the nodes will be on the same tree.  The input is terminated by N = 0.

Output

For each test case, print the pre-order of the tree.  In each level, traverse the node with smaller ID first.

Sample Input  Download

Sample Output  Download

Tags




Discuss




9029 - All combinations   

Description

Given N different digits. You have to choose M digits from them to create all possible numbers in ascending order. For example, given 3 digits "4", "5", "6", and M = 2, the possible answers are "45", "46", "54", "56", "64", "65".

Input

The first line contains a positive integer T (T <= 20), which indicates how many cases in the input. Each case starts with two positive integers N and M (1 <= M <= N <= 10), which denote the amount of the digits and the amount of digits of desired numbers. The next line contains exactly n different digits (0~9) separated by blanks.

Output

For each case, first line outputs the case number. Then, output all the possible numbers in ascending order. (See the Sample Output)

Sample Input  Download

Sample Output  Download

Tags




Discuss