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 » Knight Coders Round 2 » Gathering of the Great

Gathering of the Great

Problem code: KC202

  • All Submissions

All submissions for this problem are available.

Points:10

Evading the agents of the church was of prime importance for the Brotherhood of Brom, for if caught they would hanged, or burnt at the stake, or worse... Instead of having just a single meeting place they had multiple spots so that if one location was somehow compromised, they could use the other. Hence they needed to chose their meeting spots very carefully in the city. They chose them in such a manner that each meeting place was always connected to all the other alternate meeting spots. Last night as you were going through the junk in your attic, you came across an ancient manuscript. Turns out that it is actually a map drawn by your greatest grandfather himself of the whole city as it was at that time. You could probably track down their meeting locations by finding sets of spots on the map that were always completely interconnected. It would be easier to visualise the map as a graph with the roads as the edges and the possible meeting locations as the nodes.
Consider a graph G formed from a large number of nodes connected by edges. G is said to be connected if a path can be found in 0 or more steps between any pair of nodes in G. For example, the graph below is not connected because there is no path from A to C.
This graph contains, however, a number of subgraphs that are connected, one for each of the following sets of nodes: {A}, {B}, {C}, {D}, {E}, {A,B}, {B,D}, {C,E}, {A,B,D}
A connected subgraph is maximal if there are no nodes and edges in the original graph that could be added to the subgraph and still leave it connected. There are two maximal connected subgraphs above, one associated with the nodes {A, B, D} and the other with the nodes {C, E}.
Write a program to find the number of maximal connected subsections(subgraphs) of the city(graph).

Input:

The first line contains the number of test cases T. T<=100 The first line of each input set contains a single uppercase alphabetic character. This character represents the largest node name in the graph. Each successive line contains a pair of uppercase alphabetic characters denoting an edge in the graph. Input is terminated by #.

Output:

For each test case, the output the number of maximal connected subgraphs.

Example:

Input:
1
E
AB
CE
DB
EC
Output:
2

Author: ankitbabbar
Date Added: 16-10-2009
Time Limit: 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, 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.

in the example given, '#' is

sumit9 @ 24 Oct 2009 10:14 PM

in the example given, '#' is not shown

does it come after EC in this case?

Yeah..There is a # at the end

ankitbabbar @ 24 Oct 2009 10:19 PM

Yeah..There is a # at the end of the each input...Missed in the sample inputs..

From the problem statement it

muditjain87 @ 24 Oct 2009 11:19 PM

From the problem statement it looks like this graph is undirected. Why does the sample input have both EC and CE?

is the max nu,ber of nodes

anshulluhsna @ 24 Oct 2009 11:46 PM

is the max nu,ber of nodes 26?

@anshul: Well i think the

ankitbabbar @ 24 Oct 2009 11:52 PM

@anshul: Well i think the maximum number of characters are 26...:)

Is there a "#" after every

rahulakaneo @ 25 Oct 2009 12:17 AM

Is there a "#" after every test case , or it denotes the end of complete input file ?

There is a # after every test

ankitbabbar @ 25 Oct 2009 12:23 AM

There is a # after every test case.

Could you please provide a

rahulakaneo @ 25 Oct 2009 01:08 AM

Could you please provide a sample input(only input and not output) that has at least two test cases. I am constant getting runtime errors and think that the input format is different then what is given.

2EABBCCDEE#EABCEDBEC#

ankitbabbar @ 25 Oct 2009 01:19 AM
2
E
AB
BC
CD
EE
#
E
AB
CE
DB
EC
#

the graph is directed or

neel @ 25 Oct 2009 01:36 AM

the graph is directed or undirected??

the graph is directed

ankitbabbar @ 25 Oct 2009 01:54 AM

the graph is directed

If the graph is directed then

Shubham28 @ 25 Oct 2009 02:44 AM

If the graph is directed then the example in the question should return 1 instead of 2. This is because subgraph corresponding to{A,B,D} won't have a path from A to D and from B to either A orD hence not fulfilling the condition given in the question for a graph to be connected.This  leaved us with the only connected graph corresponding to {C,E}.

 

Please clarify.

 

 

 

 

THE GRAPH IS

ankitbabbar @ 25 Oct 2009 03:29 AM

THE GRAPH IS UNDIRECTED...There has been a wrong comment before by one of my team member.....but there can be mirrored inputs  as CE and EC are the same..

CAN A SINGLE VERTEX FORM A

neel @ 25 Oct 2009 04:57 AM

CAN A SINGLE VERTEX FORM A MAXIMAL CONNECTED SUBGRAPH??

CAN some1 answer neel's

virai @ 25 Oct 2009 01:04 PM

CAN some1 answer neel's question??? if it is entered as EE will it be counted as a subgraph??

YES, a single vertex can form

ankitbabbar @ 25 Oct 2009 01:12 PM

YES, a single vertex can form a maximal connected graph...and EE will be counted as  a subgraph..

plz can you give some other

mohitkuldeep @ 25 Oct 2009 04:10 PM

plz can you give some other test cases.

Can you please tell me the

mohitkuldeep @ 25 Oct 2009 08:16 PM

Can you please tell me the output of the following input

1

B

BB

AB

AA

#

the output will be 1

ankitbabbar @ 25 Oct 2009 08:29 PM

the output will be 1

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