×

# GRAPHCOL - Editorial

Practice

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

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".

11
accept rate: 0%

19.8k350498541

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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