CF1725I.Imitating the Key Tree
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Pak Chanek has a tree called the key tree. This tree consists of N vertices and N−1 edges. The edges of the tree are numbered from 1 to N−1 with edge i connecting vertices Ui and Vi . Initially, each edge of the key tree does not have a weight.
Formally, a path with length k in a graph is a sequence [v1,e1,v2,e2,v3,e3,…,vk,ek,vk+1] such that:
- For each i , vi is a vertex and ei is an edge.
- For each i , ei connects vertices vi and vi+1 .
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 N vertices and 2N−2 edges.
- For each pair of different vertices (x,y) , there exists a simple circuit that goes through vertices x and y in the graph.
- The weight of each edge in the graph is an integer between 1 and 2N−2 inclusive. Each edge has distinct weights.
- The graph is formed in a way such that there is a way to assign a weight Wi to each edge i in the key tree that satisfies the following conditions:
- For each pair of edges (i,j) , if i<j , then Wi<Wj .
- For each pair of different vertex indices (x,y) , the cost of the only simple path from vertex x to y in the key tree is equal to the minimum cost of a simple circuit that goes through vertices x and y 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 998244353 .
Two graphs are considered distinct if and only if there exists a triple (a,b,c) such that there exists an edge that connects vertices a and b with weight c in one graph, but not in the other.
输入格式
The first line contains a single integer N ( 2≤N≤105 ) — the number of vertices in the key tree.
The i -th of the next N−1 lines contains two integers Ui and Vi ( 1≤Ui,Vi≤N ) — an edge connecting vertices Ui and Vi . 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 998244353 .
输入输出样例
输入#1
4 3 2 1 3 4 3
输出#1
540
说明/提示
The following is an example of a graph that satisfies.
The following is an assignment of edge weights in the key tree that corresponds to the graph above.
As an example, consider a pair of vertex indices (1,4) .
- The circuit in the graph for this pair of vertices is 32244621153 with a cost of 6 .
- The path in the key tree for this pair of vertices is 15364 with a cost of 6 .