CF1725I.Imitating the Key Tree
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
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.
帕克·查内克有一棵名为“钥匙树”的树。这棵树包含 N 个顶点和 N−1 条边。树的边从 1 编号到 N−1,其中第 i 条边连接顶点 Ui 和 Vi。初始时,钥匙树的每条边均无权重。
形式化地,图中一条长度为 k 的路径是一个序列 [v1,e1,v2,e2,v3,e3,…,vk,ek,vk+1],满足:
- 对每个 i,vi 是一个顶点,ei 是一条边;
- 对每个 i,ei 连接顶点 vi 和 vi+1。
回路(circuit)是一条起点与终点为同一顶点的路径。
图中的一条路径被称为简单路径,当且仅当该路径不重复使用同一条边。注意:简单路径可以多次经过同一顶点。
在带权图中,一条简单路径的代价定义为该路径所经过的所有边中权重的最大值。
请计算满足以下条件的互不相同的无向带权图的数目:
- 该图有 N 个顶点和 2N−2 条边;
- 对任意一对不同的顶点 (x,y),图中存在一条经过顶点 x 和 y 的简单回路;
- 图中每条边的权重均为 1 到 2N−2(含端点)之间的整数,且所有边的权重互不相同;
- 该图的构造方式满足:存在一种为钥匙树中每条边 i 分配权重 Wi 的方法,使得:
- 对任意两条边 (i,j),若 i<j,则 Wi<Wj;
- 对任意一对不同的顶点索引 (x,y),钥匙树中从顶点 x 到 y 的唯一简单路径的代价,等于图中所有经过顶点 x 和 y 的简单回路的最小代价。
- 注意:图中允许存在重边,但不允许存在自环。
请将答案对 998244353 取模后输出。
当且仅当存在一个三元组 (a,b,c),使得某条连接顶点 a 和 b、权重为 c 的边在一个图中存在而在另一个图中不存在时,两个图被视为不同。
输入格式
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.
第一行包含一个整数 N(2≤N≤105)—— 表示密钥树中的顶点数量。
接下来的 N−1 行中,第 i 行包含两个整数 Ui 和 Vi(1≤Ui,Vi≤N)—— 表示连接顶点 Ui 和 Vi 的一条边。输入中的图是一棵树。
输出格式
An integer representing the number of distinct undirected weighted graphs that satisfy the conditions of the problem modulo 998244353.
一个整数,表示满足题目条件的不同无向带权图的数量对 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.
以下是满足条件的一个图示例。

以下是与上述图相对应的密钥树(key tree)中各边的权重赋值。

以顶点索引对 (1,4) 为例:
- 该顶点对在图中的回路为 32244621153,总代价为 6。
- 该顶点对在密钥树中的路径为 15364,总代价为 6。
输入解题思路,AI测评打分。不知道怎么写?