当前位置:网站首页>2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
2022-07-03 17:09:00 【Elucidation】
Edge set

quote lwz_159 My blog
C o d e : Code: Code:
#include<bits/stdc++.h>
#include<unordered_map>
#define mem(a,b) memset(a,b,sizeof a)
#define cinios (ios::sync_with_stdio(false),cin.tie(0),cout.tie(0))
#define sca scanf
#define pri printf
#define forr(a,b,c) for(int a=b;a<=c;a++)
#define rfor(a,b,c) for(int a=b;a>=c;a--)
#define endl "\n"
//[ Blog address ]:https://blog.csdn.net/weixin_51797626?t=1
using namespace std;
inline void read(int& x) {
x = 0; int f = 1; char ch = getchar(); while (ch < '0' || ch > '9') {
if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') {
x = x * 10 + (ch - '0'); ch = getchar(); } x *= f; }
void write(int x) {
if (x < 0) putchar('-'), x = -x; if (x >= 10) write(x / 10); putchar(x % 10 + '0'); }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
const int N = 100010, M = 200010, MM = N;
int INF = 0x3f3f3f3f, mod = 998244353;
ll LNF = 0x3f3f3f3f3f3f3f3f;
int n, m, k, T, S, D;
int h[N], ne[M], e[M], idx;
ll dp[N];
inline void add(int a, int b) {
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
// Determine the edges that can contribute according to the number of edges of the subtree where the child node is located
// If the number of sides is even ( Pairing within oneself ), The edges of the current node and child nodes contribute
// Otherwise, odd numbers will occupy this side
bool dfs(int x, int fa) {
int cnt = 0;
dp[x] = 1;
for (int i = h[x]; ~i; i = ne[i]) {
int j = e[i];
if (j == fa)continue;
if (!dfs(j, x))cnt++;
dp[x] = (dp[x] * dp[j]) % mod;
}
for (int i = 1; i <= cnt; i += 2)dp[x] = (dp[x] * i) % mod;
return cnt & 1;
}
int main() {
cinios;
cin >> n;
mem(h, -1);
forr(i, 1, n - 1) {
int a, b;
cin >> a >> b;
add(a, b), add(b, a);
}
dfs(1, -1);
cout << dp[1];
return 0;
}
/* */
边栏推荐
- Open vsftpd port under iptables firewall
- Kotlin learning quick start (7) -- wonderful use of expansion
- [error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.
- [combinatorics] recursive equation (constant coefficient linear homogeneous recursive equation | constant coefficient, linear, homogeneous concept description | constant coefficient linear homogeneous
- [combinatorics] recursive equation (example of solving recursive equation without multiple roots | complete process of solving recursive equation without multiple roots)
- 【RT-Thread】nxp rt10xx 设备驱动框架之--Pin搭建和使用
- Installation and configuration of network hard disk NFS
- Why is WPA3 security of enterprise business so important?
- Redis: operation commands for list type data
- 新库上线 | CnOpenData中国观鸟记录数据
猜你喜欢

SWM32系列教程4-端口映射及串口应用

Bcvp developer community 2022 exclusive peripheral first bullet

Why is WPA3 security of enterprise business so important?

C language modifies files by line
![[try to hack] active detection and concealment technology](/img/43/d48f851268fec566ce0cc83bd9557e.png)
[try to hack] active detection and concealment technology

Free data | new library online | cnopendata complete data of China's insurance intermediary outlets

29:第三章:开发通行证服务:12:开发【获得用户账户信息,接口】;(使用VO类包装查到的数据,以符合接口对返回数据的要求)(在多处都会用到的逻辑,在Controller中可以把其抽成一个共用方法)

【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用

C语言按行修改文件

Take you to API development by hand
随机推荐
New features of C 10
RedHat 6.2 configuring ZABBIX
[combinatorics] recursive equation (example 1 of recursive equation | list recursive equation)
大消费企业怎样做数字化转型?
29: Chapter 3: develop Passport Service: 12: develop [obtain user account information, interface]; (use VO class to package the found data to meet the requirements of the interface for the returned da
13mnnimo5-4 German standard steel plate 13MnNiMo54 boiler steel 13MnNiMo54 chemical properties
LeetCode 1656. Design ordered flow
静态程序分析(一)—— 大纲思维导图与内容介绍
跨境电商:外贸企业做海外社媒营销的优势
What material is 13crmo4-5 equivalent to in China? 13crmo4-5 chemical composition 13crmo4-5 mechanical properties
[combinatorics] recursive equation (the relationship theorem between the solution of the recursive equation and the characteristic root | the linear property theorem of the solution of the recursive e
在iptables防火墙下开启vsftpd的端口
Talk about several methods of interface optimization
Meituan side: why does thread crash not cause JVM crash
PHP online confusion encryption tutorial sharing + basically no solution
基于主机的入侵系统IDS
Necessary ability of data analysis
Free data | new library online | cnopendata complete data of China's insurance intermediary outlets
IL Runtime
一位普通程序员一天工作清单