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
    • February Long Contest
    • January CookOff
    • January Long Contest
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » Codechef Campus Snackdown » Powerful Strongholds

Powerful Strongholds

Problem code: SNCK02

  • All Submissions

All submissions for this problem are available.

[Problem Idea : Varun Jalan and Yu Yiu Ho]

In a small world not so far away, there is an ongoing war between two nations, A and B. There are n (3 n 20) strongholds in this world, with roads between some of them. Two strongholds are neighbors if there is a road between them, all roads are bidirectional. The Chef is at war and he recently came up with a scheme that will help his country to never lose the war. He would like to select a set of powerful strongholds (defined below) of minimum size and conquer those strongholds to ensure that his country will never be defeated. A set of powerful strongholds is a set of strongholds S, such that

1.For every stronghold y which does not belong to S, there is a road leading to it from a stronghold x which belongs to S. This way, any stronghold not in S is threatened by a stronghold in S.

2.S can properly defend (defined next) any attack from strongholds outside of S.

The mechanism for attacking and defending S is defined as follows:

i.In an attack, each single stronghold y not belonging to S will select one of its neighbor z belonging to S (if any) to attack. In this case y is an attacker of z.

ii.Given the attack routes of all y not belonging to S, each stronghold x belonging to S may decide to defend one of its neighbors, say z, in which case x is a defender of z. Alternatively, x may decide to defend itself, in which case x is a defender of x.

iii.The attack can be properly defended if there exists a defend route such that at every stronghold z belonging to S, there are at least as many defenders of z as attackers of z.

The rationale is that once the Chef occupies the strongholds in S, any other stronghold is immediately within reach of S by a single road (rule 1), and S will never be overwhelmed by attacks from outside (rule 2), and thus the Chef will never lose a stronghold in S. In order to make the task of occupying S easier, it is best if S is as small as possible. The Chef has given you the task to identify the smallest set of powerful strongholds so that he can proceed with his plan.

 

Input:

There will be multiple test cases. Each test case is a specification of the strongholds and roads. For each test case, there will be one line containing n (3 <= n <= 20), the number of strongholds, and r (0 <= r <= 190), the number of roads. Then, the next r lines each contains two integers x and y giving a road between stronghold x and y. The strongholds are numbered from 0 to n-1. There is a blank line following each test case. The last test case is followed by a line containing two zeros (after the blank line).

Output:

For each test case, output a single line of integers. The first integer is |S|, represents size of the smallest possible set of powerful strongholds. The next |S| integers give one such possible set of strongholds. If there are multiple possible answers for S, output the lexicographically smallest one.

Sample Input:

3 2
0 1
1 2

6 6
0 1
1 2
2 3
3 4
4 5
5 0

5 10
0 1
0 2
0 3
0 4
1 2
1 3
1 4
2 3
2 4
3 4

0 0

Sample Output:

2 0 1
4 0 1 2 3
3 0 1 2



Date: 2009-11-13
Time limit: 5

s
Source limit: 50000
Languages: C C99 strict C++ 4.0.0-8 C++ 4.3.2 PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp SCALA HASK ERL CAML CLPS PRLG WSPC BF ICK JS


  • Submit

Comments

  • Login or Register to post a comment.

if a stronghold can only

sanity_eclipse @ 21 Nov 2009 07:40 PM

if a stronghold can only attack its neighbour how come the ans for 2nd test case is 4,

consider case where only 0,1 is chosen, then only 5,2 can attack and hence can be defended.. what am i missing?

Can there be simultaneous

Kratos313 @ 21 Nov 2009 08:21 PM

Can there be simultaneous attacks? If so, can a specific stronghold support the defence of both attacks at the same time?

Fuck all those

busted @ 21 Nov 2009 09:19 PM

Fuck all those strongholds!

Believe me.....reconsider my suggestions assholes!!!!!!!!

 

Theres no difference in your brains and your assholes.

@sanity_eclipse : You are

syco @ 21 Nov 2009 10:31 PM

@sanity_eclipse :
You are missing rule 1 :
any stronghold must be in S or reachable by traveling only 1 road from S

@ Kushagra Udai :The answer

syco @ 21 Nov 2009 10:34 PM

@ Kushagra Udai :

The answer is yes: every vertex not in S can attack a vertex in S, which in some sense vertices in S are being attacked simultaneously.  This also means some vertex in S may be attacked by multiple enemy strongholds. But, any vertex noy in S can only attack one vertex of S

How many tests are there in

tnu2 @ 21 Nov 2009 10:55 PM
How many tests are there in this proplem?

So what was the solution?

SlodziakiUWr @ 22 Nov 2009 03:32 AM

So what was the solution?

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 computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various 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 judge accepts solutions in over 35+ programming languages. Online programming was 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 competitions 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 programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

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. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

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