You are not logged in. Please login at www.codechef.com to post your questions!

×

GRAPHCOL - Editorial

PROBLEM LINK:

Practice

Author: Aman Kumar Gupta Tester: D Teja Vardhan Reddy Editorialist: Aman Kumar Gupta

DIFFICULTY:

EASY-MEDIUM

PREREQUISITES:

Graph theory, Combinatorics

PROBLEM:

A short and concise description of the problem statement.

QUICK EXPLANATION:

Given a graph with N nodes and M - 1 edges. You have also been given K colours and you are required to find the number of ways to colour the nodes which can be reached from-and-to each other using the same colour, and the ones not reachable in both ways, with different colours.

EXPLANATION:

Basically, it's clear from the problem itself that the nodes which are reachable from-and-to each other form strongly connected components. So, we just need to find the number of strongly connected components. Let this count be 's'. Then if K is less than 's', answer is -1. Else the answer is k! / (k - s)!.

AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution can be found here.

Tester's solution can be found here.

This question is marked "community wiki".

asked 07 Feb, 00:01

aman_58472's gravatar image

4★aman_58472
11
accept rate: 0%

edited 07 Feb, 20:15

admin's gravatar image

0★admin ♦♦
19.8k350498541

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,678
×1,218
×888
×22

question asked: 07 Feb, 00:01

question was seen: 118 times

last updated: 07 Feb, 20:15