[Solution] Imitating the Key Tree Codeforces Solution
Pak Chanek has a tree called the key tree. This tree consists of vertices and edges. The edges of the tree are numbered from to with edge connecting vertices and . Initially, each edge of the key tree does not have a weight.
Formally, a path with length in a graph is a sequence such that:
- For each , is a vertex and is an edge.
- For each , connects vertices and .
A circuit is a path that starts and ends on the same vertex.
A path in a graph is said to be simple if and only if the path does not use the same edge more than once. Note that a simple path can use the same vertex more than once.
The cost of a simple path in a weighted graph is defined as the maximum weight of all edges it traverses.
Count the number of distinct undirected weighted graphs that satisfy the following conditions:
- The graph has vertices and edges.
- For each pair of different vertices , there exists a simple circuit that goes through vertices and in the graph.
- The weight of each edge in the graph is an integer between and inclusive. Each edge has distinct weights.
- The graph is formed in a way such that there is a way to assign a weight to each edge in the key tree that satisfies the following conditions:
- For each pair of edges , if , then .
- For each pair of different vertex indices , the cost of the only simple path from vertex to in the key tree is equal to the minimum cost of a simple circuit that goes through vertices and in the graph.
- Note that the graph is allowed to have multi-edges, but is not allowed to have self-loops.
Print the answer modulo .
Two graphs are considered distinct if and only if there exists a triple such that there exists an edge that connects vertices and with weight in one graph, but not in the other.
The first line contains a single integer () — the number of vertices in the key tree.
The -th of the next lines contains two integers and () — an edge connecting vertices and . The graph in the input is a tree.
An integer representing the number of distinct undirected weighted graphs that satisfy the conditions of the problem modulo .
No comments:
Post a Comment