[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5141 [算法] 树形DP 时间复杂度 : O(N) [代码] #include<bits/stdc++.h> using namespace std; typedef long long LL; ; ; ; struct edge { int to , nxt; } e[MAXN << ]; int n , k , tot; int color[MAXN] , hea…
题目描述 Farmer John has a large farm with NN barns (1 \le N \le 10^51≤N≤105 ), some of which are already painted and some not yet painted. Farmer John wants to paint these remaining barns so that all the barns are painted, but he only has three paint co…
设\(f[i][j]\)为\(i\)子树,当\(i\)为\(j\)时的方案数 #include <bits/stdc++.h> using namespace std; #define int long long const int N = 1000005; const int mod = 1e+9+7; vector <int> g[N]; int vis[N],n,m,t1,t2,f[N][4],c[N]; void dfs(int p) { vis[p]=1; int fla…