EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • 🇲🇾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🥰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. CodeNection
  2. 2023
  3. Preliminary Round

Codey and Painted Tree

https://www.hackerrank.com/contests/codenection-2023-preliminary-round-closed-category/challenges/cn-c7

Question

Codey loves solving challenging problems, and today, Codey faces a unique task.

A tree is a connected and undirected graph without cycles. Codey is given a tree with n nodes and n-1 edges. Initially, every node in the tree is painted white. Codey can choose to paint some of the nodes black. Codey's goal is to find the number of ways to paint the tree such that, in each of these ways, the number of unique b-path is exactly m. Codey is excited to tackle this problem and find a solution.

A b-path is a sequence of nodes v1,v2,...,vkv_1, v_2, ..., v_kv1​,v2​,...,vk​ ,where k≥2k \ge 2k≥2 and it follows these rules:

  • Each adjacent pair of nodes in the sequence is connected by an edge.

  • Each node in the sequence is distinct.

  • It starts in a node painted black and ends in a node painted black.

Two b-paths are considered different if the sets of nodes used in the sequence are different.

Your task is to help Codey solve this problem and output the number of valid ways to paint the tree, considering the restrictions, and then return the answer modulo 109+710^9 + 7109+7. Recall that a modulo b is the remainder of when a divided by b.

Input Format

The first line contains two integers, n and m, where n represents the number of nodes in the tree, and m represents the number of b-path.

Then following n-1 lines describe the tree, where each of them contain two integers u, v, which represents the endpoints of the corresponding edge.

Constraints

1≤n≤1051 \le n \le 10^51≤n≤105
1≤m≤10181 \le m \le 10^{18}1≤m≤1018

Output Format

Output the number of ways to paint the tree with m b-path modulo 109+710^9 + 7109+7.

Sample Inputs:

Input

3 1
1 2
2 3

Output

3

Explanation

One of the ways to paint the tree is as follows:

There is only 1 b-path when you paint node 3 and node 1 in black, which can be represented by the sequence of nodes [1,2,3]. Note that b-path [1,2,3] is the same as [3,2,1] since the set of nodes used in the sequence is the same.

Input

5 1
1 4
2 5
3 2
4 3

Output

10

Solution - Haven't finish yet

-- If you know the solution please tell me, I am not good on trees. --

PreviousCodey and Team SelectionNextCodey and Number Grid

Last updated 5 months ago

🇲🇾