当前位置:网站首页>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;
}
/* */
边栏推荐
- What material is 13crmo4-5 equivalent to in China? 13crmo4-5 chemical composition 13crmo4-5 mechanical properties
- 免费数据 | 新库上线 | CnOpenData中国保险中介机构网点全集数据
- [2. Basics of Delphi grammar] 1 Identifiers and reserved words
- 美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃
- RedHat 6.2 配置 Zabbix
- Necessary ability of data analysis
- 人生还在迷茫?也许这些订阅号里有你需要的答案!
- 大变局!全国房价,跌破万元大关
- 建立自己的网站(23)
- Analysis of variance summary
猜你喜欢
新库上线 | CnOpenData中国保险机构网点全集数据
[error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.
【RT-Thread】nxp rt10xx 设备驱动框架之--Pin搭建和使用
聊聊接口优化的几个方法
One brush 145 force deduction hot question-2 sum of two numbers (m)
[try to hack] active detection and concealment technology
Network security web penetration technology
图之深度优先搜索
UCORE overview
Recommendation of good books on learning QT programming
随机推荐
人生还在迷茫?也许这些订阅号里有你需要的答案!
Analysis of variance summary
[try to hack] active detection and concealment technology
Unity notes unityxr simple to use
[combinatorics] recursive equation (example of solving recursive equation without multiple roots | complete process of solving recursive equation without multiple roots)
Life is still confused? Maybe these subscription numbers have the answers you need!
Kotlin learning quick start (7) -- wonderful use of expansion
New library online | cnopendata complete data of Chinese insurance institution outlets
How do large consumer enterprises make digital transformation?
Informatics Olympiad all in one YBT 1175: divide by 13 | openjudge noi 1.13 27: divide by 13
深入理解 SQL 中的 Grouping Sets 语句
Redis:关于列表List类型数据的操作命令
[JDBC] API parsing
kubernetes资源对象介绍及常用命令(四)
The largest matrix (H) in a brush 143 monotone stack 84 histogram
图之深度优先搜索
C语言字符串反转
Host based intrusion system IDS
How to allow remote connection to MySQL server on Linux system?
[2. Basics of Delphi grammar] 2 Object Pascal data type