Language: C++

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)-form-)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };


template <class N, class E>
struct Rerooting {
	int n;
	const vector<vector<E>>& G;
	vector<N> subtreesum;
	vector<vector<N>> dp; // L
	void dfs1(int v, int p) {
		subtreesum[v] = N();
		for (auto e : G[v]) {
			int nx = e.to;
			if (nx == p) continue;
			dfs1(nx, v);
			subtreesum[v] = subtreesum[v] + subtreesum[nx].include_e(v, e);
		}
		subtreesum[v] = subtreesum[v].include_v(v);
	}
	void dfs2(int v, int p, N top) {
		int deg = int(G[v].size());
		dp[v] = vector<N>(deg + 1);
		dp[v][0] = N();
		for (int i = 0; i < deg; i++) {
			int nx = G[v][i].to;
			dp[v][i + 1] =
				dp[v][i] + (nx == p ? top : subtreesum[nx]).include_e(v, G[v][i]);
		}
		N rnode = N();
		dp[v].back() = dp[v].back().include_v(v);
		for (int i = deg - 1; i >= 0; i--) {
			dp[v][i] = (dp[v][i] + rnode).include_v(v);
			int nx = G[v][i].to;
			if (nx != p) dfs2(nx, v, dp[v][i]);
			rnode = rnode + (nx == p ? top : subtreesum[nx]).include_e(v, G[v][i]);
		}
	}
	Rerooting(const vector<vector<E>>& _g) : n(int(_g.size())), G(_g), subtreesum(n), dp(n) {
		dfs1(0, -1);
		dfs2(0, -1, N());
	}
};
template <class N, class E> vector<vector<N>> Rerooting_get(const vector<vector<E>>& g) {
	return Rerooting<N, E>(g).dp;
}

class GModInt {
public:
	static int Mod;	int x; GModInt() : x(0) { }GModInt(signed sig) { if ((x = sig % Mod + Mod) >= Mod) x -= Mod; }GModInt(signed long long sig) { if ((x = sig % Mod + Mod) >= Mod) x -= Mod; }int get() const { return x; }	GModInt &operator+=(GModInt that) { if ((x += that.x) >= Mod) x -= Mod; return *this; }	GModInt &operator-=(GModInt that) { if ((x += Mod - that.x) >= Mod) x -= Mod; return *this; }GModInt &operator*=(GModInt that) { x = (unsigned long long)x * that.x % Mod; return *this; }GModInt &operator/=(GModInt that) { return *this *= that.inverse(); }GModInt operator+(GModInt that) const { return GModInt(*this) += that; }GModInt operator-(GModInt that) const { return GModInt(*this) -= that; }GModInt operator*(GModInt that) const { return GModInt(*this) *= that; }GModInt operator/(GModInt that) const { return GModInt(*this) /= that; }GModInt inverse() const { long long a = x, b = Mod, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }return GModInt(u); }bool operator==(GModInt that) const { return x == that.x; }bool operator!=(GModInt that) const { return x != that.x; }GModInt operator-() const { GModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
int GModInt::Mod = 0;
typedef GModInt mint;

struct Node {
	mint black = 1;
	Node include_e(int, const Edge&e) const {
		return { (black + 1) };
	}
	Node operator + (const Node& r) const {
		return { (black * r.black) };
	}
	Node include_v(int v) const {
		return *this;
	}
};

void solve_EDPC_V() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	struct Edge {
		int to;
	};


	int N; cin >> N;
	vector<vector<Edge>>G(N);
	int M; cin >> M;
	GModInt::Mod = M;
	FOR(i, 0, N - 1) {
		int a, b; cin >> a >> b;
		a--, b--;
		G[a].push_back(Edge({b}));
		G[b].push_back(Edge({a}));
	}

	auto tree_res = Rerooting_get<Node>(G);
	FOR(i, 0, N) {
		cout << tree_res[i].back().black.get() << endl;
	}

}

int main() {
	solve_EDPC_V();

}

Compiler output:
a.cc:80:35: error: 'Edge' does not name a type
   80 |         Node include_e(int, const Edge&e) const {
      |                                   ^~~~
a.cc: In instantiation of 'void Rerooting<N, E>::dfs1(int, int) [with N = Node; E = solve_EDPC_V()::Edge]':
a.cc:63:3:   required from 'Rerooting<N, E>::Rerooting(const std::vector<std::vector<_ValT> >&) [with N = Node; E = solve_EDPC_V()::Edge]'
   63 |                 dfs1(0, -1);
      |                 ^~~~
a.cc:68:9:   required from 'std::vector<std::vector<_Tp> > Rerooting_get(const std::vector<std::vector<_ValT> >&) [with N = Node; E = solve_EDPC_V()::Edge]'
   68 |         return Rerooting<N, E>(g).dp;
      |                ^~~~~~~~~~~~~~~~~~
a.cc:111:37:   required from here
  111 |         auto tree_res = Rerooting_get<Node>(G);
      |                         ~~~~~~~~~~~~~~~~~~~^~~
a.cc:40:85: error: cannot convert 'solve_EDPC_V()::Edge' to 'const int&'
   40 |                         subtreesum[v] = subtreesum[v] + subtreesum[nx].include_e(v, e);
      |                                                                                     ^
      |                                                                                     |
      |                                                                                     solve_EDPC_V()::Edge
a.cc:80:40: note:   initializing argument 2 of 'Node Node::include_e(int, const int&) const'
   80 |         Node include_e(int, const Edge&e) const {
      |                             ~~~~~~~~~~~^
a.cc: In instantiation of 'void Rerooting<N, E>::dfs2(int, int, N) [with N = Node; E = solve_EDPC_V()::Edge]':
a.cc:64:3:   required from 'Rerooting<N, E>::Rerooting(const std::vector<std::vector<_ValT> >&) [with N = Node; E = solve_EDPC_V()::Edge]'
   64 |                 dfs2(0, -1, N());
      |                 ^~~~
a.cc:68:9:   required from 'std::vector<std::vector<_Tp> > Rerooting_get(const std::vector<std::vector<_ValT> >&) [with N = Node; E = solve_EDPC_V()::Edge]'
   68 |         return Rerooting<N, E>(g).dp;
      |                ^~~~~~~~~~~~~~~~~~
a.cc:111:37:   required from here
  111 |         auto tree_res = Rerooting_get<Node>(G);
      |                         ~~~~~~~~~~~~~~~~~~~^~~
a.cc:51:86: error: cannot convert 'const __gnu_cxx::__alloc_traits<std::allocator<solve_EDPC_V()::Edge>, solve_EDPC_V()::Edge>::value_type' {aka 'const solve_EDPC_V()::Edge'} to 'const int&'
   51 |                                 dp[v][i] + (nx == p ? top : subtreesum[nx]).include_e(v, G[v][i]);
      |                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
a.cc:80:40: note:   initializing argument 2 of 'Node Node::include_e(int, const int&) const'
   80 |         Node include_e(int, const Edge&e) const {
      |                             ~~~~~~~~~~~^
a.cc:59:83: error: cannot convert 'const __gnu_cxx::__alloc_traits<std::allocator<solve_EDPC_V()::Edge>, solve_EDPC_V()::Edge>::value_type' {aka 'const solve_EDPC_V()::Edge'} to 'const int&'
   59 |                         rnode = rnode + (nx == p ? top : subtreesum[nx]).include_e(v, G[v][i]);
      |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
a.cc:80:40: note:   initializing argument 2 of 'Node Node::include_e(int, const int&) const'
   80 |         Node include_e(int, const Edge&e) const {
      |                             ~~~~~~~~~~~^