2707 - I2P(I)2022_Hu_Lab12 Scoreboard

Time

2023/01/02 18:40:00 2023/01/02 20:40:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
13391 Domo the Train Conductor
13786 Camo's Christmas Tree

13391 - Domo the Train Conductor   

Description

Domo is a train conductor, he wants to adjust the train he's driving.

 

There are five instructions below with the description:

 

1. AddFront num

Add a train carriage with the index num in front of the train.

 

2. AddBack num

Add a train carriage with the index num in back of the train.

 

3. Delete num

Delete all the train carriages with the index num from the train. (If the train has no any carriage with the index num, do nothing)

 

4. DeleteFront

Delete the first element of the train. (If the train is empty, do nothing)

 

5. Swap

Reverse all train carriages. (If the train is empty, do nothing)

 

For example:

AddFront 5 makes the train [4, 1] become [5, 4, 1].

AddBack 5 makes the train [4, 1] become [4, 1, 5].

Delete 5 makes the train [5, 4, 1, 5, 3] become [4, 1, 3].

DeleteFront make the train [1, 2, 3, 4] become [2, 3, 4].

Swap makes the train [2, 6, 3] become [3, 6, 2].

 

The train is empty in the beginning. Given a series of instructions, please print the index of train carriages after all instructions are executed.

 

This is a partial judge problem, you're asked to implement these 5 functions.

 

If you get a TLE:

Try to use the pointer head and back wisely, which can make the AddFront and AddBack instructions faster!

 

If you get an MLE:

Remember to free the nodes you've deleted!

 

Input

The input consists of multiple instructions (1 ≤ number of instructions ≤ 105)

 

the index of each instruction is a positive integer and not greater than 102.

 

Output

The output only consists of a line denoting the train carriage indices after all the instructions.

 

It's guaranteed that the output consists of at least one carriage.

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

13391.c

Partial Judge Header

13391.h

Tags




Discuss




13786 - Camo's Christmas Tree   

Description

Camo is a brilliant cat, she wants to find a perfect size Christmas tree, could you help her?

 

There's a tree with N nodes; the root is node 1.

 

The size of node i is the sum of the value of all nodes in the subtree whose root is node i.

 

Given an interger X, can you find the size of node X ?

 

Here's an example. The following image describes a tree and the member of node 3's subtreenode 6's subtree, and node 4's.

The sample input is the same as the tree above, you can find further information from it.

 

Hint: the size of node 1 to node 10 is

[19, 2, 10, 4, 7, 2, 1, 2, 1, 1]

 

Input

Given two integers N and X, which represent the number of nodes in the tree and X. (1 ≤ N ≤ 1000, ≤ X ≤ N)

 

The next line consists of N integers (V1, V2, ..., VN), representing the value of nodes. (0 ≤ Vi ≤ 20)

 

For the following N-1 lines, each line consists of two numbers i and j, representing an edge between node i and node j. (1 ≤ i, j ≤ N)

 

Output

Output the size of node X, and remember to print a newline character at the end of the line.

 

Sample Input  Download

Sample Output  Download

Tags




Discuss