CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » June 2010 Contest » Robots on Map

Robots on Map

Problem code: TR2

  • All Submissions

All submissions for this problem are available.

NOTE: The problem statement has been updated on June 3rd 2010 at 10:00pm Indian Standard Time.

Byteland is a kingdom of islands. Alice has N maps of the different islands constituting Byteland. Map of each island consists of cities, connected by roads. Being Byteland, the road layout of each island has a binary tree structure. Each island has a capital, which is the root of the binary tree of its map.

Alice is bored and plays the following game:
She chooses k out of these N maps and places a robot on the capital city of each map. Every robot is controlled by a common control string. If the present character of the control string is L(R), then all the robots move to the left(right) subtree on their map. All the robots follow the same control string and move on their respective maps.

A control string is valid with respect to a given map if it corresponds to a valid path on that map. A control string is considered valid for a given set of k maps if it is valid for each of the k chosen maps.

For example in a complete binary tree of 3 nodes, control strings "L" and "R" are valid and "LL" is an example of an invalid control string.

 

Alice is interested in knowing the longest control string which is valid for at least k maps, for each value of k. Can you find this for her?

Input

First line of input contains an integer t (t<=5), the number of test cases. Each test case starts with an integer M (1<=M<=100), the number of maps. Then M maps description follow.
The ith map description starts with an integer N (2<=N<=1000), the number of cities on the island. Each of the following N-1 lines contain two space separated integers u c v (1<=u,v<=N , c=L or R) which means a road between city u and city v on the ith island and if c is L(R) then v is in the left(right) subtree of u. The capital city of each island is the city with number 1.

Output

For each test case output M space separated integers, where the ith integer denotes the length of the longest valid control string she can obtain assuming she can choose i maps.

Example

Input:
2
3
5
1 L 2
1 R 3
3 L 4
3 R 5
4
1 R 2
1 L 3
2 L 4
3
1 L 2
1 R 3
2
5
1 L 2
2 L 3
3 L 4
4 L 5
6
1 L 2
2 R 3
3 L 4
4 R 5
5 L 6


Output:
2 2 1
5 1


Author: akhilravidas
Date Added: 10-04-2010
Time Limit: 2 - 5 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

Is the empty control string

narri @ 1 Jun 2010 05:11 PM

Is the empty control string (and therefore an answer of 0) valid?

output 'M' space seperated

aru777 @ 1 Jun 2010 09:47 PM

output 'M' space seperated integers, right?

@Aravind: Yes, output M

pieguy @ 1 Jun 2010 10:23 PM

@Aravind: Yes, output M integers.

what does "(...) which is

MarcAndreson @ 2 Jun 2010 12:59 AM

what does "(...) which is valid for at least k maps, for each value of k" mean? what is this "each value of k" ? if k is equal to 3, then "each value" is 0,1,2,3 ?

i think the output for the

sankikhopadi @ 2 Jun 2010 01:22 AM

i think the output for the 1st map of the 2nd case is wrong..It should be-- 4 1---the longest control string being LLLL..Plz tell me guys if i am wrong..

The input specification is a

vector9x @ 2 Jun 2010 07:31 AM

The input specification is a bit messy:

"...which means a road between city s and city t"

s and t is the same as u and v?

I AGREE WITH VISHAL .......

AnoopNarang @ 2 Jun 2010 01:30 PM

I AGREE WITH VISHAL ....... PLZ SUM1 EXPLAIN ....

The output is correct. Read

triplem @ 2 Jun 2010 01:31 PM

The output is correct. Read the problem statement again. (For example, vishal refers to 'the output for the first map'; you aren't meant to output an answer for 'the first map'.)

I think Out put would

sharifruet @ 2 Jun 2010 04:36 PM

I think Out put would be

Output:
2 2 1
5 1

Am I right?

Sorry--Output:2 2 14 1Am I

sharifruet @ 2 Jun 2010 04:38 PM
Sorry--
Output:

2 2 1
4 1

Am I right?

what is meaning of tym limit

dabbcomputers @ 2 Jun 2010 05:55 PM

what is meaning of tym limit 2-5 s is it 2.5 sec.???

Plz sum1 xpalin da problem

sankikhopadi @ 2 Jun 2010 09:21 PM

Plz sum1 xpalin da problem !!!!

@admin what is the time limit

dabbcomputers @ 3 Jun 2010 01:38 AM

@admin

what is the time limit for this problem.....???

@Chris, yes @Aravind, it is M

akhil_adm @ 3 Jun 2010 04:28 PM

@Chris, yes

@Aravind, it is M space seperated integers

@vishal, it means that it is a multiple input problem and each input file has an associated time limit. The lowest is 2s and the highest time limit is 5s.

@Amritpal, it is dependent on the test case file. Any good solution should pass in less than 2s

comment removed by admin

codegambler @ 4 Jun 2010 09:49 AM

comment removed by admin

@pankaj: you are not supposed

suh_ash2008 @ 4 Jun 2010 10:21 AM

@pankaj: you are not supposed to discuss approaches to the problem. You will be disqualified. Read FAQ !

what does "(...) which is

MarcAndreson @ 5 Jun 2010 07:18 PM

what does "(...) which is valid for at least k maps, for each value of k" mean?

what is this "each value of k" ?

plz answer...

"1 is always the capital", is

crazysaikat @ 6 Jun 2010 10:35 PM

"1 is always the capital", is it necessary that 1st line of map description is always 1 c v(c=LorR, 1<=v<=n)??

Please some one help... and post some gud test cases..

@Marc, You must output the

akhil_adm @ 7 Jun 2010 03:30 PM

@Marc, You must output the answer for every possible value that k can take.

@Saikat, you can assume that all inputs strictly follow the given input description and nothing more

Are test cases usually posted

Tool @ 10 Jun 2010 09:49 PM

Are test cases usually posted after the contest? I would really like to know which one is giving me TLE when I've been fast on all the huge test cases i've generated

@Tedrick you can find the

akhil_adm @ 11 Jun 2010 05:09 PM

@Tedrick you can find the program used to generate all the inputs (before splitting them) here: http://pastebin.com/Ek10cPKZ

Since the input was fairly large, It could have been your I/O routines which were causing the TLE.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com