Ways To Add One Route Closing A Same Region Cycle Of Three Or More Stations

Company: D. E. Shaw_18jul

Difficulty: medium

Problem Statement

Problem Description A large bus company recently expanded its fleet to enhance its in-house transportation system. These buses travel to specific stations, numbered from 1 to n . The company operates in two regions, and all bus routes form a tree : buses departing from any station go to a local hub, then travel to a larger hub or one of the company's destinations. Stations in the first region are coloured white ( 0 ) and stations in the second region black ( 1 ). Given the stations and their immediate destinations, add a route between any two stations so that a perfect route cycle is formed. A perfect route cycle is one where: the number of destinations in the cycle is greater than or equal to 3 , and all stations in the cycle are in the same region . Count the number of distinct ways to form a perfect route cycle by adding a single route between two stations. Input Format The first line contains two integers tree_nodes and m , the number of stations and the number of existing routes.