A13465 | Independent Set
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Eric is the teacher of graph theory class. Today, Eric teaches independent set and edge-induced subgraph.
Given a graph $G=(V,E)$ , an independent set is a subset of vertices $V' \subset V$ such that for every pair $u,v \in V'$ , $(u,v) \not \in E$ (i.e. no edge in $E$ connects two vertices from $V'$ ).
An edge-induced subgraph consists of a subset of edges $E' \subset E$ and all the vertices in the original graph that are incident on at least one edge in the subgraph.
Given $E' \subset E$ , denote $G[E']$ the edge-induced subgraph such that $E'$ is the edge set of the subgraph. Here is an illustration of those definitions:
In order to help his students get familiar with those definitions, he leaves the following problem as an exercise:
Given a tree $G=(V,E)$ , calculate the sum of $w(H)$ over all except null edge-induced subgraph $H$ of $G$ , where $w(H)$ is the number of independent sets in $H$ . Formally, calculate $\sum \limits_{\emptyset \not= E' \subset E} w(G[E'])$ .
Show Eric that you are smarter than his students by providing the correct answer as quickly as possible. Note that the answer might be large, you should output the answer modulo $998,244,353$ .
Given a graph $G=(V,E)$ , an independent set is a subset of vertices $V' \subset V$ such that for every pair $u,v \in V'$ , $(u,v) \not \in E$ (i.e. no edge in $E$ connects two vertices from $V'$ ).
An edge-induced subgraph consists of a subset of edges $E' \subset E$ and all the vertices in the original graph that are incident on at least one edge in the subgraph.
Given $E' \subset E$ , denote $G[E']$ the edge-induced subgraph such that $E'$ is the edge set of the subgraph. Here is an illustration of those definitions:
In order to help his students get familiar with those definitions, he leaves the following problem as an exercise:
Given a tree $G=(V,E)$ , calculate the sum of $w(H)$ over all except null edge-induced subgraph $H$ of $G$ , where $w(H)$ is the number of independent sets in $H$ . Formally, calculate $\sum \limits_{\emptyset \not= E' \subset E} w(G[E'])$ .
Show Eric that you are smarter than his students by providing the correct answer as quickly as possible. Note that the answer might be large, you should output the answer modulo $998,244,353$ .
输入格式
The first line contains a single integer $n$ ( $2 \le n \le 3 \cdot 10^5$ ), representing the number of vertices of the graph $G$ .
Each of the following $n-1$ lines contains two integers $u$ and $v$ ( $1 \le u,v \le n$ , $u \not= v$ ), describing edges of the given tree.
It is guaranteed that the given edges form a tree.
Each of the following $n-1$ lines contains two integers $u$ and $v$ ( $1 \le u,v \le n$ , $u \not= v$ ), describing edges of the given tree.
It is guaranteed that the given edges form a tree.
输出格式
Output one integer, representing the desired value modulo $998,244,353$ .
输入输出样例
输入 #1
2 2 1
输出 #1
3
输入 #2
3 1 2 3 2
输出 #2
11
For the second example, all independent sets are listed below.


C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted