output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; long long d[100005]; long long flag[100005]; long long c[100005]; long long r[100005]; vector<int> q[100005]; int mod = 1e9 + 7; long long cf(long long x, int p) { long long y = 1; while (p) { if (p % 2) { y = y * x % mod; p--; } else { p /= 2;...
### Prompt Your task is to create a cpp solution to the following problem: Today is Devu's birthday. For celebrating the occasion, he bought n sweets from the nearby market. He has invited his f friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't want ...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); } template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); } template <class T> inline T ison(T n...
### Prompt Create a solution in Cpp for the following problem: Today is Devu's birthday. For celebrating the occasion, he bought n sweets from the nearby market. He has invited his f friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't want any friend t...
#include <bits/stdc++.h> using namespace std; namespace Flandre_Scarlet { long long I() { long long x = 0; char c = getchar(); long long f = 1; while (c < '0' or c > '9') f = (c == '-') ? -1 : 1, c = getchar(); while (c >= '0' and c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return (x = ...
### Prompt Please provide a Cpp coded solution to the problem described below: Today is Devu's birthday. For celebrating the occasion, he bought n sweets from the nearby market. He has invited his f friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't w...
#include <bits/stdc++.h> using namespace std; long long jie[100010], ni[100010]; int miu[100010]; long long power(long long x, int y) { if (y == 1) return x; else { long long tmp = power(x, y / 2); tmp = tmp * tmp % 1000000007; if (y % 2 == 1) return tmp * x % 1000000007; else return...
### Prompt Generate a cpp solution to the following problem: Today is Devu's birthday. For celebrating the occasion, he bought n sweets from the nearby market. He has invited his f friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't want any friend to ...
#include <bits/stdc++.h> using namespace std; const long long sz = 1e5 + 10, mod = 1e9 + 7; vector<long long> dv[sz]; long long dp[sz], fact[sz], inv[sz], totalWay[sz]; unordered_map<int, int> ret[sz]; long long fastPow(long long x, long long n, long long MOD) { long long ret = 1; while (n) { if (n & 1) ret = (...
### Prompt Your task is to create a Cpp solution to the following problem: Today is Devu's birthday. For celebrating the occasion, he bought n sweets from the nearby market. He has invited his f friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't want ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7, N_MAX = 1e5; int n; vector<int> gr[N_MAX + 2]; bool col[N_MAX + 2]; int dp[N_MAX + 2][2]; void dfs(int arg) { dp[arg][0] = !col[arg]; dp[arg][1] = col[arg]; for (auto it : gr[arg]) { dfs(it); int aux0 = dp[arg][0], aux1 = dp[arg][1]; ...
### Prompt Please provide a CPP coded solution to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; int n, clr[100005]; vector<int> adj[100005]; long long dp[100005][2]; long long bigmod(long long x, int pow) { long long ret = 1; while (pow > 0) { if (pow & 1) ret = (ret * x) % 1000000007; x = (x * x) % 1000000007; pow /= 2; } return ret; } long long d...
### Prompt Please formulate a CPP solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const int modul = 1000000007; const int nmax = 100100; const double e = 1e-8; const double pi = acos(-1); int n, m, stest, c[nmax], F[nmax][2], G[nmax]; vector<int> head[nmax]; void DFS(int u) { F[u][0] = (c[u] == 0); for (int i = 0; i <= (int)head[u].size() - 1; i++) {...
### Prompt Your challenge is to write a CPP solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; int n, x, cnt; bool col[200010]; long long dp[200010][2], p[200010], a[200010], b[200010]; vector<int> vs[200010]; void dfs(int u, int fa) { if (vs[u].size() == 1 && fa != 0) { if (col[u]) { dp[u][0] = 0; dp[u][1] = 1; } else { dp[u][0] = 1; ...
### Prompt In Cpp, your task is to solve the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it ...
#include <bits/stdc++.h> using namespace std; int abs(int x) { if (x < 0) return -x; return x; } int addmod(int v1, int v2) { int v3 = v1 + v2; if (v3 >= 1000000007) v3 -= 1000000007; return v3; } long long dp[100005][2]; long long old[100005][2]; int color[100005]; vector<int> vv[100005]; void dfs(int pos) {...
### Prompt Develop a solution in cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; vector<int> graph[100005]; bool visited[100005]; bool black[100005]; long long int dp[100005][2]; long long int p = 1000000007; void dfs(int n) { visited[n] = 1; if (black[n]) { dp[n][1] = 1; dp[n][0] = 0; } else { dp[n][0] = 1; dp[n][1] = 0; } for...
### Prompt Your task is to create a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; struct edge { int v, nxt; }; int n; const int MOD = 1000000007; edge e[200020]; int g[100010]; int nume; int color[100010]; long long f[100010][2]; void addedge(int u, int v) { e[++nume].v = v; e[nume].nxt = g[u]; g[u] = nume; e[++nume].v = u; e[nume].nxt = g[v]...
### Prompt Generate a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it wil...
#include <bits/stdc++.h> using namespace std; const int N = 100000; const long long MOD = 1000000007; int n, p[N], x[N]; vector<int> graph[N]; long long colored[N], not_colored[N]; void dfs(int u) { if (x[u] == 0) { long long haveNone = 1; long long haveOne = 0; not_colored[u] = 1; for (int ed = 0; ed...
### Prompt In CPP, your task is to solve the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7, N = 1e5 + 5; vector<int> adj[N], col(N); long long dp[N][2]; void dfs(int u, int p = 0) { dp[u][col[u]] = 1; for (auto v : adj[u]) { if (v == p) continue; dfs(v, u); dp[u][1] = (dp[u][0] * dp[v][1] + dp[u][1] * (dp[v][0] + dp[v][1]))...
### Prompt Develop a solution in cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const long long mXn = 1e5 + 10, M = 1e9 + 7; vector<long long> ad[mXn]; bool b[mXn], mark[mXn]; long long dp0[mXn], dp1[mXn]; void dfs(long long v) { if (b[v]) { dp1[v] = 1; } else { dp0[v] = 1; } mark[v] = true; for (long long i = 0; i < (long long)ad[v]....
### Prompt Develop a solution in cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const long mod = 1000000007; vector<int> adj[200000]; long color[200000]; long long dp[200000][2]; long n; void dfs(long u) { dp[u][color[u]] = 1; long v; for (int k = 0; k < adj[u].size(); k++) { v = adj[u][k]; dfs(v); dp[u][1] = ((dp[u][1] * dp[v][1]) % ...
### Prompt Generate a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it wil...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void Cin(T &x) { char c; T sign = 1; x = 0; for (c = getchar(); c < '0' || c > '9'; c = getchar()) if (c == '-') sign = -1; for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sign; } const int N = 1e5 + 7; con...
### Prompt Please provide a Cpp coded solution to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; vector<int> graph[100010]; int arr[100010] = {0}; int vis[100010] = {0}; long long dp[100010][2]; void dfs(int u) { vis[u] = 1; dp[u][0] = 1 - arr[u]; dp[u][1] = arr[u]; vector<int>::iterator vec; for (vec = graph[u].begin(); vec != graph[u].end(); vec++) { in...
### Prompt Your task is to create a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAXN = 1e5 + 10; vector<int> G[MAXN]; int color[MAXN]; long long dp[MAXN][2]; void init() { for (int i = 0; i < MAXN; i++) { G[i].clear(); } } long long qpow(long long x, long long k) { long long res = 1; while (k > 0) { if...
### Prompt Generate a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it wil...
#include <bits/stdc++.h> using namespace std; int N; vector<int> adj[100001]; int color[100001]; long long dp[100001][2]; void dfs(int node) { dp[node][0] = 1; dp[node][1] = 0; for (int X : adj[node]) { dfs(X); dp[node][1] *= dp[X][0]; dp[node][1] += dp[node][0] * dp[X][1]; dp[node][0] *= dp[X][0]...
### Prompt Your challenge is to write a CPP solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, x, dp[123456][2], p[123456], mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); ; cin >> n; for (i = 1; i < n; i++) { cin >> p[i]; } for (i = 0; i < n; i++) { cin >> x; dp[i][x] = 1; } for (i = n - 1; i; i--) { dp[...
### Prompt Develop a solution in Cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long dp[100004][2]; int n; vector<int> g[100004]; int v[100004]; void dfs(int x) { dp[x][v[x]] = 1; for (int i = 0; i < g[x].size(); i++) { int y = g[x][i]; dfs(y); dp[x][1] = dp[x][1] * (dp[y][0] + dp[y][1]) % MOD; dp...
### Prompt Your task is to create a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int M = 1e9 + 7; enum Color { W, B }; int n, x[N], p[N], f[N][2]; vector<int> g[N]; void Dfs(int u) { f[u][W] = (x[u] == W); f[u][B] = (x[u] == B); for (auto v : g[u]) { int t[2]; memcpy(t, f[u], sizeof(t)); Dfs(v); t[W] =...
### Prompt In Cpp, your task is to solve the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 100005; const long long MOD = 1000000007; template <class T> inline void read(T &x) { x = 0; int f = 0; char ch = getchar(); while (ch < '0' || ch > '9') { f |= (ch == '-'); ch = getchar(); } while (ch >= '0' && ...
### Prompt Please create a solution in Cpp to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > G; vector<int> COLOR; vector<vector<long long> > DP; const long long mod = 1e9 + 7; void solve(int vId, int parentId) { if (G[vId].size() > 1 || vId == 0) { for (int i = 0; i < G[vId].size(); ++i) { if (parentId != G[vId][i]) solve(G[vId][i]...
### Prompt Please provide a Cpp coded solution to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; using dd = long double; namespace { static bool constexpr dbg = 0; ll constexpr N = 1.1e5, MO = 1e9 + 7; ll n, d[N][2]; bool bl[N]; vector<ll> adj[N]; void init() { cin >> n; for (ll i = 1; i <= (ll)(n - 1); ++i) { ll ...
### Prompt Create a solution in CPP for the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it w...
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int mod = 1e9 + 7; int n, col[N]; long long dp[N][2]; vector<int> adj[N]; void dfs(int u) { dp[u][0] = 1LL; dp[u][1] = 0LL; for (auto v : adj[u]) { dfs(v); dp[u][1] = (dp[u][1] * dp[v][0]) % mod; dp[u][1] = (dp[u][1] + (dp[v][1]...
### Prompt Your challenge is to write a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; const int MaxN = 1000005; const double eps = 1e-8; const double DINF = 1e100; const int INF = 1000000006; const long long LINF = 1000000000000000005ll; const int mod = (int)1e9 + 7; int n; int color[MaxN]; vector<int> edges[MaxN]; long long f[MaxN][2]; long long tmp[MaxN][2...
### Prompt Develop a solution in Cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; int n; const int mo = 1000000007; const int N = 200000; long long f[N][2]; int t[N], s[N]; int main() { scanf("%d", &n); for (int i = 0; i < n - 1; i++) scanf("%d", t + i + 1); for (int i = 0; i < n; i++) { scanf("%d", &s[i]); f[i][s[i]] = 1; } for (int i ...
### Prompt Construct a Cpp code solution to the problem outlined: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then i...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } int power(int a, int b, int m, int ans = 1) { for (; b; b >>= 1, a = 1LL * a * a % m) if (b & 1)...
### Prompt Generate a CPP solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it wil...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e5 + 10; const int mod = (int)1e9 + 7; int p[maxn]; long long d[maxn][2]; int n, x; int main() { scanf("%d", &n); for (int i = 0; i < n - 1; i++) scanf("%d", p + i + 1); for (int i = 0; i < n; i++) { scanf("%d", &x); d[i][x] = 1; } f...
### Prompt Please create a solution in cpp to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; vector<int> adj[100050]; int b[100050]; long long dp[100050][2]; const int m = 1e9 + 7; void dfs(int v, int p) { long long old[2] = {0}; dp[v][0] = 1 - b[v]; dp[v][1] = b[v]; for (auto u : adj[v]) { if (u == p) continue; old[0] = dp[v][0]; old[1] = dp[v]...
### Prompt Please formulate a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; template <class T> inline T _sq(T a) { return a * a; } template <class T> inline T _sqrt(T a) { return (T)sqrt((double)a); } template <class T, class X> inline T _pow(T a, X y) { T z = 1; for (int i = 1; i <= y; i++) { z *= a; } return z; } template <class T...
### Prompt Develop a solution in CPP to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, N = 1e5 + 5; int n, c[N], x; long long dp[N][2]; vector<int> g[N]; void dfs(int v) { dp[v][0] = 1LL; for (int u : g[v]) { dfs(u); (dp[u][0] += dp[u][1]) %= mod; dp[v][1] = (dp[v][1] * dp[u][0] + dp[v][0] * dp[u][1]) % mod; dp[v][...
### Prompt Your challenge is to write a CPP solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; int sgn(double x) { return (x > 1e-8) - (x < -1e-8); } int count_bit(int x) { return x == 0 ? 0 : count_bit(x >> 1) + (x & 1); } template <class T> inline void ckmin(T &a, const T b) { if (b < a) a = b; } template <class T> inline void ckmax(T &a, const T b) { if (b > a...
### Prompt Please formulate a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000007; const long long BIG = 1446803456761533460LL; const int Big = 336860180; const long long int INF = LONG_LONG_MAX; const vector<vector<long long int> > adj4({{0, 1}, {0, -1}, {1, 0}, {-1, 0}}); const vector<vector<long long int> > adj8( ...
### Prompt In cpp, your task is to solve the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 1; const int INF = 0x3f3f3f3f; const double eps = 1e-8; const int mod = 1e9 + 7; int a[maxn]; long long dp[maxn][2]; int main() { int n; scanf("%d", &n); for (int i = 1; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < n; i++) { ...
### Prompt Please formulate a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; vector<long long int> adj[100005]; long long int n; long long int bw[100005]; long long int dp[100005][2]; void dfs(long long int x) { dp[x][1] = 0; dp[x][0] = 1; for (auto it : adj[x]) { dfs(it); dp[x][1] = (dp[it][0] % 1000000007 * dp[x][1] % 1000000007) % 1...
### Prompt Your challenge is to write a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; int x[100000]; vector<int> adj[100000]; void add(int &a, int b) { a = (a + b) % 1000000007; } int mul(int a, int b) { return (long long)a * b % 1000000007; } pair<int, int> dfs(int u) { pair<int, int> ret = {1, 0}; for (int v : adj[u]) { pair<int, int> p = dfs(v); ...
### Prompt Please provide a Cpp coded solution to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; long long int dp[2][200000]; int p[200000]; vector<int> v[200000]; int col[200000]; long long int modexp(long long int a, long long int b) { long long int ret = 1; while (b) { if ((b & 1)) { ret *= a; ret %= 1000000007; } a *= a; a %= 1000000...
### Prompt Please provide a cpp coded solution to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; int c[100009]; vector<int> v[100009]; long long dp[100009][2]; void dfs(int x) { dp[x][c[x]] = 1; for (int i = 0; i < v[x].size(); i++) { int y = v[x][i]; dfs(y); dp[x][1] = ((dp[x][0] * dp[y][1]) % 1000000007 + (dp[x][1] * dp[y][1]) % 100000...
### Prompt In CPP, your task is to solve the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it ...
#include <bits/stdc++.h> using namespace std; const int oo = 2000000009; const double eps = 1e-9; list<int> adj[100005]; int label[100005]; long long dp[100005][2]; const long long MOD = 1000000007; void numWays(int v, int p) { dp[v][0] = 1 - label[v]; dp[v][1] = label[v]; for (typeof(adj[v].begin()) u = adj[v].b...
### Prompt Develop a solution in cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const int MAX = 100005; int B[MAX], N; long long DP[MAX][2]; vector<int> E[MAX]; void dfs(int n, int p) { DP[n][1] = B[n]; DP[n][0] = 1 - B[n]; for (int v : E[n]) if (v != p) { long long old[2]; old[0] = DP[n][0]; ...
### Prompt Please create a solution in cpp to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const int M = 100005; long long dp[M][2]; vector<int> G[M]; int color[M]; void dfs(int x) { long long ones, zeros; ones = color[x]; zeros = 1 - color[x]; int u; for (int i = 0; i < G[x].size(); i++) { u = G[x][i]; dfs(u); ones = (ones * dp[u][1] + ones...
### Prompt Please provide a CPP coded solution to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; long long dp[MAXN][2]; vector<int> x[MAXN]; int c[MAXN]; void dfs(int v, int p) { dp[v][0] = 1; dp[v][1] = 0; for (int i = 0; i < x[v].size(); ++i) { int u = x[v][i]; if (u == p) continue; dfs(u, v); dp[v][1] = ((dp[v][1] * dp[...
### Prompt Develop a solution in CPP to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; template <class T> inline T _sq(T a) { return a * a; } template <class T> inline T _sqrt(T a) { return (T)sqrt((double)a); } template <class T, class X> inline T _pow(T a, X y) { T z = 1; for (int i = 1; i <= y; i++) { z *= a; } return z; } template <class T...
### Prompt Generate a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it wil...
#include <bits/stdc++.h> using namespace std; const long long N = 3e5; const long long P = 1e9 + 7; long long n; long long col[N], f[N], g[N]; vector<long long> a[N]; long long read(void) { long long s = 0, w = 0; char c = getchar(); while (!isdigit(c)) w |= c == '-', c = getchar(); while (isdigit(c)) s = s * 1...
### Prompt Your task is to create a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; string alpha = "abcdefghijklmnopqrstuvwxyz"; const long long mod = 1e9 + 7; const long long inf = 2e18 + 5; const long long nax = 100010; vector<vector<long long>> g; bool x[nax]; long long dp[nax][2]; void dfs(long long u) { dp[u][0] = 1; dp[u][1] = 0; for (auto v : ...
### Prompt Generate a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it wil...
#include <bits/stdc++.h> using namespace std; long long pow(long long a, long long b) { if (b == 0) return 1; long long res = pow(a, b / 2); res *= res; res %= 1000000007; if (b % 2 == 1) res *= a; return res % 1000000007; } long long rev(long long x) { return pow(x, 1000000007 - 2); } long long color[10800...
### Prompt In CPP, your task is to solve the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it ...
#include <bits/stdc++.h> using namespace std; const long long MX = 2e5; vector<long long> adj[MX]; const long long MOD = 1e9 + 7; long long mult(long long x, long long y) { return (x * y) % MOD; } long long add(long long x, long long y) { return (x + y) % MOD; } long long fastPow(long long a, long long b) { long long...
### Prompt Your challenge is to write a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; const int sz = 200010; vector<int> g[sz]; long long int a[sz], dp[sz][2]; void dfs(int u, int p) { dp[u][0] = 1; dp[u][1] = 0; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (v != p) { dfs(v, u); dp[u][1] = (dp[u][1] * dp[v][0] % 10000...
### Prompt Please provide a CPP coded solution to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> graph; vector<int> isBlack; vector<long long> dp[2]; long long previous[2]; void dfs(int curr) { dp[0][curr] = 1 - isBlack[curr]; dp[1][curr] = isBlack[curr]; for (int child : graph[curr]) { dfs(child); previous[0] = dp[0][curr]; previo...
### Prompt Please create a solution in Cpp to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; int mod; int n; map<int, vector<int> > ch; int col[100001]; bool seen[100001]; int dp[100001][2]; void dfs(int r) { if (seen[r]) return; seen[r] = true; dp[r][0] = 1; dp[r][1] = 0; for (int i = 0; i < ch[r].size(); ++i) { int u = ch[r][i]; if (seen[u]) con...
### Prompt Your challenge is to write a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; const int N = 100005; vector<int> g[N]; const int mod = 1e9 + 7; long long dp[N][2]; int color[N]; int n; void dfs(int x) { dp[x][0] = 1; dp[x][1] = 0; for (int i = 0; i < g[x].size(); i++) { dfs(g[x][i]); dp[x][1] = (dp[x][1] * dp[g[x][i]][0] + dp[x][0] * dp[...
### Prompt Your task is to create a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; bool c[100000]; vector<int> v[100000]; long long a[2][100000]; int const md = 1000000007; void dfs(int n) { if (c[n]) { a[1][n] = 1; a[0][n] = 0; for (int i = 0; i < v[n].size(); ++i) { int h = v[n][i]; dfs(h); a[1][n] *= (a[0][h] + a[1][h]);...
### Prompt Develop a solution in CPP to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; long long getpow(long long a, long long b) { long long ret = 1LL; long long inter = a % 1000000007; while (b) { if (b & 1) { ret *= inter; ret %= 1000000007; } inter *= inter; inter %= 1000000007; b = b >> 1; } return ret; } int n, ...
### Prompt In CPP, your task is to solve the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it ...
#include <bits/stdc++.h> using namespace std; const int N = 100001; int n, k; vector<vector<int> > adjList(N); vector<int> nxt(N, -1); bool color[N]; int dp[N][2][2]; void dfs(int node) { bool leaf = true; for (int i = 0; i < adjList[node].size(); i++) { leaf = false; int ch = adjList[node][i]; int next...
### Prompt Please create a solution in Cpp to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int MAX = 1e9 + 5; long long q[100005], prefix[100005], x, postfix[100005], dp[100005][2], col[100005], i, j, k, n, m; vector<int> v[100005], tv[100005]; void dfs(int node, int root) { if (root != -1) v[root].push_back(node); for (__type...
### Prompt Construct a cpp code solution to the problem outlined: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then i...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; long long max(long long a, long long b) { if (a > b) { return a; } else { return b; } } long long min(long long a, long long b) { if (a < b) { return a; } else { return b; } } long long power(long long b, long long e...
### Prompt Your task is to create a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; vector<long long> whs; vector<long long> bs; vector<vector<int> > T; vector<bool> color; long long m = 1000000007; void fill_dp(int v) { if (T[v].size() == 0) { if (color[v]) { whs[v] = 0; bs[v] = 1; } else { bs[v] = 0; whs[v] = 1; } ...
### Prompt Please provide a cpp coded solution to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> const int MAX_N = 2e5 + 5; const int MODULO = 1000000007; int N; std::vector<int> children[MAX_N]; std::bitset<MAX_N> isBlack; long long memo[MAX_N][2]; long long f(int vertex, bool blackAbove); int gcdExtended(int a, int b, int *x, int *y) { if (a == 0) { *x = 0, *y = 1; return b; ...
### Prompt Create a solution in CPP for the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it w...
#include <bits/stdc++.h> using namespace std; const int MM = 300005; int n; int x[MM]; long long dp[MM][2]; vector<int> a[MM]; void DP(int u) { dp[u][0] = 1; dp[u][1] = 0; for (int i = 0; i < a[u].size(); i++) { int v = a[u][i]; DP(v); dp[u][1] = (dp[u][0] * dp[v][1] + dp[u][1] * dp[v][0]) % 100000000...
### Prompt Please formulate a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const double eps(1e-8); const double pi(3.14159265358979); const int N = 100100, mod = 1000000007; int n; int color[N] = {}; long long f[N][2] = {}; vector<int> v[N]; void init() { scanf("%d", &n); for (int i = 2, x = 0; i <= n; ++i) { scanf("%d", &x); v[x + 1]....
### Prompt Your task is to create a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; vector<int> e[100007]; long long val_array[100007]; long long val_array2[100007]; int color[100007]; int borw[100007]; int count1[100007]; void count_black(int v) { if (color[v]) return; color[v] = 1; if (borw[v]) count1[v] = 1; for (int i = 0; i < e[v].size(); i++)...
### Prompt Please create a solution in Cpp to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; vector<int> g[100010]; long long dp[100010][2]; long long num = 1e9 + 7; int col[100010]; void dfs(int cur, int par) { dp[cur][col[cur]] = 1; for (int i = 0; i < g[cur].size(); i++) { if (g[cur][i] != par) { dfs(g[cur][i], cur); dp[cur][1] = (dp[cur][1] ...
### Prompt Develop a solution in Cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { a %= 1000000007; long long int res = 1; while (b > 0) { if (b & 1) res = res * a % 1000000007; a = a * a % 1000000007; b >>= 1; } return res; } long long int modinv(long long int p) { return power...
### Prompt Develop a solution in cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int mod = 1000000007; long long dp[maxn][2]; int x[maxn]; int n; vector<int> G[maxn]; void DP(int u) { dp[u][x[u]] = 1; for (int i = 0; i < G[u].size(); i++) { int son = G[u][i]; DP(son); dp[u][1] = (dp[u][1] * dp[son][1] % mo...
### Prompt Your task is to create a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; long long xyp(long long x, long long y) { if (y == 0) return 1LL; if (y == 1) return x; if (y % 2) { long long p = xyp(x, y - 1); return (x * p) % 1000000007; } long long p = xyp(x, y / 2); return (p * p) % 1000000007; } long long inv(long long x) { retu...
### Prompt Create a solution in cpp for the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it w...
#include <bits/stdc++.h> using namespace std; struct listNode { long long int n; listNode *next; listNode(long long int n = 0LL) : n(n), next(NULL) {} }; long long int num; listNode *edge[100100], *tail[100100]; long long int color[100100]; void insertEdge(long long int a, long long int b) { if (!edge[a]) { ...
### Prompt Create a solution in Cpp for the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it w...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int N = 100000 + 10; int n; vector<int> adj[N]; int color[N]; unsigned long long dp[N][2]; unsigned long long pow_mod(unsigned long long x, int n, unsigned long long mod) { unsigned long long ret = 1; while (n...
### Prompt Your task is to create a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> template <class T> T read(T &a) { a = 0; char x = getchar(); bool f = 0; for (; x < '0' || x > '9'; x = getchar()) f |= x == '-'; for (; x >= '0' && x <= '9'; x = getchar()) a = (a << 3) + (a << 1) + x - '0'; if (f) a = -a; return a; } using namespace std; const int N = 2e5 + 5, M...
### Prompt Please formulate a CPP solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const long long int M = 1e5 + 7; const long long int mod = 1e9 + 7; const long long int infi = LLONG_MAX; long long int ans, k, n, x, y, m, mymax = LLONG_MIN, mymin = LLONG_MAX, b, c, z, sum; long long int dp[M][2]; long long int color[M], ...
### Prompt Generate a CPP solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it wil...
#include <bits/stdc++.h> using namespace std; double eps = 1e-9; const int INF = 1e9; const int MOD = 1e9 + 7; const int N = 1e5 + 7; long long dp[N][2]; vector<int> g[N]; int x[N]; void dfs(int v, int p) { dp[v][0] = 1; dp[v][1] = 0; for (int to : g[v]) { if (to != p) { dfs(to, v); dp[v][1] = (dp...
### Prompt Develop a solution in Cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const long long P = 1000000007LL; const int maxN = 110000; vector<int> g[maxN]; int n; int c[maxN]; long long d[2][maxN]; long long dp[maxN][2]; void dfs(int v) { for (int i = 0; i < g[v].size(); ++i) { dfs(g[v][i]); } i...
### Prompt Your task is to create a CPP solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; const int N = (int)200004; const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; char dir[] = {'L', 'D', 'R', 'U'}; const long long int mod = (long long int)1e9 + 7; const long long int inf = 1e18 + 1000; int BIT[200005], n; long long i...
### Prompt Develop a solution in cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; inline long long read() { char i = getchar(); long long f = 1, res = 0; while (i < '0' || i > '9') { if (i == '-') f = -1; i = getchar(); } while (i >= '0' && i <= '9') { res = res * 10 + i - '0'; i = getchar(); } return res * f; } const int N ...
### Prompt Construct a cpp code solution to the problem outlined: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then i...
#include <bits/stdc++.h> const long base = 97; using namespace std; long long n, a[1000005]; vector<long> G[1000005]; long long F[1000005][2]; void nhap() { cin >> n; long x; for (long i = 1; i < n; i++) { cin >> x; G[x].push_back(i); } for (long i = 0; i < n; i++) cin >> a[i]; } void DFS(long v) { ...
### Prompt Your task is to create a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; struct node { long long end, next; } g[100100 * 2]; long long fa[100100], tot, n, i, ok[100100], x, f[100100][2]; long long ksm(long long a, long long b) { long long tem = 1ll; while (b) { if (b & 1) tem = tem * a % 1000000007; a = a * a % 1000000007; b >>...
### Prompt Your task is to create a CPP solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; const unsigned long long MOD = 1e9 + 7; const int MAXN = 1e5 + 5; int n; int *color; vector<int> *child; unsigned long long dp[MAXN][2]; int main() { scanf("%d", &n); child = new vector<int>[n]; for (int i = 0; i < n - 1; ++i) { int x; scanf("%d", &x); chi...
### Prompt Please formulate a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; vector<long long int> v[100005]; long long int c[100005]; long long int ans[100005][2]; void dfs(long long int s, long long int pa = -1) { ans[s][0] = 1; ans[s][1] = 0; for (auto i : v[s]) { if (i == pa) continue; dfs(i, s); ans[s][1] *= ans[i][0]; ans...
### Prompt Your task is to create a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; int p[100010]; long long d[100010][2]; int main(void) { int n, xi; scanf("%d", &n); for (int i = 0; i < n - 1; ++i) { scanf("%d", &p[i + 1]); } for (int i = 0; i < n; ++i) { scanf("%d", &xi); d[i][xi] = 1; } for (int i = n - 1; i > 0; --i) { d[...
### Prompt Develop a solution in Cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; vector<int> adj[100005]; int color[100005]; int n; int dp[100005][2]; void go(int u, int p) { for (int i = 0; i < adj[u].size(); ++i) { int v = adj[u][i]; if (v == p) continue; go(v, u); } if (color[u]) dp[u][1] = 1; else dp[u][0] = 1; for (int...
### Prompt Please create a solution in CPP to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const int maxn = 111111; const int MOD = 1e9 + 7; int n; int a[maxn]; struct Edge { int next, v; } e[2 * maxn]; int en = 0; int head[maxn]; void add(int x, int y) { e[en].v = y; e[en].next = head[x]; head[x] = en++; } bool u[maxn]; long long f[maxn][2]; void dfs(int...
### Prompt Please create a solution in CPP to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const int MOD = 1000000007; int N; int a[MAXN]; vector<int> ch[MAXN]; int dp[MAXN][2]; inline int add(int x, int y) { x += y; if (x >= MOD) x -= MOD; return x; } inline int mul(int x, int y) { return (long long)x * y % MOD; } void load() { s...
### Prompt Please provide a CPP coded solution to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; vector<int> G[100001]; long long dp[100001][2], p[100001]; void dfs(int v, int pre) { dp[v][0] = 1 - p[v]; dp[v][1] = p[v]; for (int i = 0; i < G[v].size(); i++) { int nxt = G[v][i]; if (nxt == pre) continue; dfs(nxt, v); ...
### Prompt Construct a Cpp code solution to the problem outlined: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then i...
#include <bits/stdc++.h> using namespace std; inline void OPEN(const string &s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int n, p[100100], c[100100]; vector<int> child[100100]; long long power(long long a, long long b) { if (b == 0) return 1; long long temp = pow...
### Prompt Create a solution in cpp for the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it w...
#include <bits/stdc++.h> using namespace std; const int N = 200020; vector<int> g[N]; int cor[N]; int mod = 1000 * 1000 * 1000 + 7; long long dp[N][2][2]; long long fpow(long long b, long long e) { if (!e) return 1; long long r = fpow(b, e / 2); r = (r * r) % mod; return e % 2 ? (r * b) % mod : r; } long long s...
### Prompt Develop a solution in cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const long long modulo = 1e9 + 7; const int MAXN = 200000; int colours[MAXN + 5]; vector<int> children[MAXN + 5]; long long combinations[MAXN + 5][2]; void dfs(int node) { if (colours[node] == 1) { combinations[node][0] = 0; combinations[node][1] = 1; } else { ...
### Prompt Your challenge is to write a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; const int MOD = 1e9 + 7; int dp[N][2]; int col[N]; vector<int> child[N]; long long bpow(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } void dfs(i...
### Prompt Your task is to create a CPP solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; using lli = long long int; using pii = pair<int, int>; using vi = vector<int>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vlli = vector<long long int>; using vpii = vector<pair<int, int>>; lli n, x, dp[200005][2], f[2]; vlli col; vvi adj; void dfs(int u...
### Prompt In cpp, your task is to solve the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T _sq(T a) { return a * a; } template <class T> inline T _sqrt(T a) { return (T)sqrt((double)a); } template <class T, class X> inline T _pow(T a, X y) { T z = 1; for (int i = 1; i <= y; i++) { z *= a; } return z; } template <class T...
### Prompt Develop a solution in Cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; vector<int> adj[200001]; vector<int> x(200001); vector<vector<long long> > dp(200001, vector<long long>(2)); void dfs(int node, int parent) { int i; dp[node][0] = 1; dp[node][1] = 0; for (i = 0; i < adj[node].size(); i++) { if (adj[node][i] == parent) continue; ...
### Prompt Please create a solution in CPP to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; using namespace std; long long n, mark[200009], dp[200009][2], col[200009], mod = 1e9 + 7, ans = 1, x; vector<long long> g[200009]; long long xgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { ...
### Prompt Your challenge is to write a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int mod = 1e9 + 7; int n, dp1[maxn], dp[maxn], c[maxn]; vector<int> v[maxn]; void enter() { cin >> n; for (int i = 0; i < n - 1; ++i) { int x; cin >> x; v[x].push_back(i + 1); v[i + 1].push_back(x); } for (int i = 0; i...
### Prompt Develop a solution in cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-12; const int inf = 2000000000; long long int MOD = 1000000007; int MOD1 = 1000000007; int MOD2 = 1000000009; inline bool checkBit(long long int n, long long int i) { return n & (1LL << i); } inline long long int setBit(lo...
### Prompt Construct a cpp code solution to the problem outlined: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then i...
#include <bits/stdc++.h> using namespace std; const int N = 100 * 1001, MOD = 1e9 + 7; long long n, dp[N][2]; long long r[N], l[N]; bool black[N]; vector<int> adj[N]; long long _mul(long long a, long long b) { return (1LL * a * b) % MOD; } long long _sum(long long a, long long b) { return (a + b) % MOD; } void dfs(int ...
### Prompt In Cpp, your task is to solve the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it ...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target( \ "avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; long long MOD = 1e9 + 7; const int N = 200000; vector<long long> gr[N]; long long sz[N]; long long st(long long t, long long id, long long mod) { ...
### Prompt Please formulate a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; void EE(int a, int b, int& x, int& y) { if (a % b == 0) { x = 0; y = 1; return; } EE(b, a % b, x, y); int temp = x; x = y; y = temp - y * (a / b); } int inverse(int a, int m) { int x, y; EE(a, m, x, y); if (x < 0) x += ...
### Prompt Your task is to create a Cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...
#include <bits/stdc++.h> using namespace std; constexpr long long mod = 1000000007; pair<long long, long long> dfs(int v, const vector<vector<int>> &children, const vector<int> &black) { long long zero = 0; long long one = 0; (black[v] ? one : zero) = 1; for (const auto &child : c...
### Prompt Develop a solution in Cpp to the problem described below: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, the...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; const int mod = 1000000007; long long dp[maxn][2]; vector<int> G[maxn]; int col[maxn]; void gcd(long long a, long long b, long long &d, long long &x, long long &y) { if (!b) { d = a; x = 1; y = 0; } else { gcd(b, a % b, d, y, x);...
### Prompt Your task is to create a cpp solution to the following problem: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≀ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tre...