Submit | All submissions | Best solutions | Back to list |
Problem hidden on 2012-05-17 12:03:26 by :D
PT07K - Balloons of JiaJia |
In WinD's birthday, JiaJia opens a small contest for all guests: just typing all characters from 'a' to 'z', who fastest is the winner. The award is a very big bunch of balloons. Of course, JiaJia hopes his girlfriend - WinD can win, since he only carries two bunches with him and the award for this contest looks prettier. Unfortunately, life is not always as he expected, the winner is Amber. So JiaJia can only give WinD his second bunch of balloons. After the party ended, WinD said "I prefer that bunch of balloons to this one!! If you can't give me something the same as it, I don't want to see you anymore!". Well, JiaJia really has a brainstorm.
If we consider balloons as nodes, the colorful strings connect them as edges, and color of each balloon is label of each node then we have each bunch of balloons is a rooted, labeled, ordered tree.
We call T a labeled tree if each node is assigned a symbol from a fixed finite alphabet. And T is an ordered tree if a left-to-right order among siblings in T is given.
JiaJia can do these 3 operators to change the shape of a bunch of balloons (T):
- Relabel (recolor a balloon) Change the label of a node v in T.
- Delete (remove a balloon) Delete a non-root node v in T with parent p, making the children of v become the children of p. The children are inserted in the place of v as a subsequence in the left-to-right order of the children of p.
- Insert (add a balloon) The complement of Delete. Insert a node v with any label as a child of node p in T, making v be the parent of a consecutive subsequence of the children of p.


Please help the poor guy JiaJia, use as few number of operators to make WinD's bunch of balloons exactly the same as Amber's bunch of balloons. His girlfriend can't wait any longer. Note that, he can only make changes with WinD's bunch.
Input
The input file contains two bunches of balloons (or trees). The first is of WinD, the second is of Amber.
The first line of the input file contains one integer N - number of balloons in the bunch T1 (1 <= N <= 500). Balloons are numbered from 1 to N.
In next N lines, the i-th line contains the ordered children list of the i-th balloon. The first integer l[i] of the i-th line is the color id of the i-th balloon (0 <= l[i] <= 104). The second integer c[i] of the i-th line c[i] is the number of the children of the i-th balloon. Then c[i] integers followed, which means the ordered children list of the i-th balloon.
The remaining part of the input file is the description of the second bunch of balloons T2. The format is the same as T1.
Output
Output minimum number of operators JiaJia needs to do.
Example
Input: 3 1 2 2 3 2 0 1 0 2 1 1 2 3 0 Output: 2Explanation
We cut the string connected between 1st balloon and 3rd balloons, then change the color of 2nd balloon to 3.
Added by: | Thanh-Vy Hua |
Date: | 2007-04-07 |
Time limit: | 0.100s-1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ERL JS-RHINO NODEJS PERL6 VB.NET |
Resource: | Co-author Amber |
hide comments
2012-05-17 10:05:03 :D
Time limit seems too strict. The problem will remain hidden until limits loosened. Also rejudge all the submissions, since they could run faster now than for example two years ago. |
|
2009-03-21 06:21:11 [Trichromatic] XilinX
The time limit is too tight for this problem... This is the reason why in a very long time this problem has almost zero submissions... EDIT: Oh, I remember that during the contest the constraint is n<=300, so it's easier to pass it... Last edit: 2009-03-21 06:21:11 |
|
2009-03-09 03:12:24 Carlos Eduardo Rodrigues Alves [USJT]
Is the time limit correct for this problem? I tried several approaches (one of my own and three from distinct papers) and nothing works. It seems that the 10th case takes too long. I'm testing my solutions in the TREESIM problem, which is basically this problem, and my solution is currently the fastest. |