F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Dynamic Cactus

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 86    Accepted Submission(s): 2


Problem Description
Calcuate the longest simple path of a cactus which supports adding nodes and circles.
 

Input
First line contains a single integer $Cases \leq 5$ which denotes the number of test cases.

For each case , first line contains a single integer $T$ which denotes the number of operations.

Note nodes number with 1.Firstly,we only have one node numbered 1.

For each operation, there are two positive integer $x$ and $g$,which denote the linked node and the number of adding nodes.

We let p donates the number of nodes before adding.

If g=1 , we add a node which links p+1 .

If g>1 , we add a circle p+1,p+2,...,p+g ,p+1 and p+g link with x ,p+i links with p+i+1 $(1 \leq i < g)$.

The number of added nodes for each case not exceeding $10^{5}$.
 

Output
For each case, output the answer after operating in a single line.
 

Sample Input
2 2 1 1 1 1 2 1 1 1 3
 

Sample Output
1 2 1 4
 

Hint

A simple path is a path in a graph which does not have repeating vertices.
The cactus is a graph which each edge belong to at most one simple circle.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-04 19:28:21, Gzip enabled