Language: C++

ll N, M;
ll MAX = 1e5+5;
vector<ll> DP(MAX), DP2(MAX);
vector<vector<ll>> G(MAX);


int dfs(ll x, ll p){
    ll res = 1;
    for(auto v : G[x]){
        if(v == p) continue;
        res *= (dfs(v, x)+1);
        res %= M;
    }
    DP[x] = res;
    return DP[x];
}

void dfs2(ll x, ll p = -1){
    vector<ll> pt;
    for(auto v : G[x]) if(v != p) pt.push_back(v);
    vector<ll> Acc1, Acc2; Acc1.push_back(1); Acc2.push_back(1);
    for(auto v : pt){
        if(v == p) continue;
        Acc1.push_back(DP[v]+1);
        Acc2.push_back(DP[v]+1);
    }Acc1.push_back(1); Acc2.push_back(1);

    for(int i = 0; i < Acc1.size()-1; i++) {Acc1[i+1] *= Acc1[i]; Acc1[i+1] %=M;}
    for(int i = Acc2.size()-1; i > 0; i--) {Acc2[i-1] *= Acc2[i]; Acc2[i-1] %=M;}

    for(int i = 0; i < pt.size(); i++){
        ll idx = i+1;
        ll v = pt[i];
        DP2[v] = (((Acc1[idx-1] * Acc2[idx+1])%M) * DP2[x])%M + 1;
    }
    for(auto v : G[x]){
        if(p != v)dfs2(v, x);
    }
}

int main(){
    cin >> N >> M;
    DP.resize(N);
    DP2.resize(N);
    G.resize(N);
    for(int i = 0; i < N-1; i++){
        ll a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, -1);
    DP2[0] = 1;

    dfs2(0);

    for(int i = 0; i < N; i++) cout << (DP[i]*DP2[i])%M << endl;

}

Compiler output:
a.cc:1:1: error: 'll' does not name a type
    1 | ll N, M;
      | ^~
a.cc:2:1: error: 'll' does not name a type
    2 | ll MAX = 1e5+5;
      | ^~
a.cc:3:1: error: 'vector' does not name a type
    3 | vector<ll> DP(MAX), DP2(MAX);
      | ^~~~~~
a.cc:4:1: error: 'vector' does not name a type
    4 | vector<vector<ll>> G(MAX);
      | ^~~~~~
a.cc:7:9: error: 'll' was not declared in this scope
    7 | int dfs(ll x, ll p){
      |         ^~
a.cc:7:15: error: 'll' was not declared in this scope
    7 | int dfs(ll x, ll p){
      |               ^~
a.cc:7:19: error: expression list treated as compound expression in initializer [-fpermissive]
    7 | int dfs(ll x, ll p){
      |                   ^
a.cc:18:6: error: variable or field 'dfs2' declared void
   18 | void dfs2(ll x, ll p = -1){
      |      ^~~~
a.cc:18:11: error: 'll' was not declared in this scope
   18 | void dfs2(ll x, ll p = -1){
      |           ^~
a.cc:18:17: error: 'll' was not declared in this scope
   18 | void dfs2(ll x, ll p = -1){
      |                 ^~
a.cc: In function 'int main()':
a.cc:42:5: error: 'cin' was not declared in this scope
   42 |     cin >> N >> M;
      |     ^~~
a.cc:42:12: error: 'N' was not declared in this scope
   42 |     cin >> N >> M;
      |            ^
a.cc:42:17: error: 'M' was not declared in this scope
   42 |     cin >> N >> M;
      |                 ^
a.cc:43:5: error: 'DP' was not declared in this scope
   43 |     DP.resize(N);
      |     ^~
a.cc:44:5: error: 'DP2' was not declared in this scope
   44 |     DP2.resize(N);
      |     ^~~
a.cc:45:5: error: 'G' was not declared in this scope
   45 |     G.resize(N);
      |     ^
a.cc:47:9: error: 'll' was not declared in this scope
   47 |         ll a, b; cin >> a >> b; a--; b--;
      |         ^~
a.cc:47:25: error: 'a' was not declared in this scope
   47 |         ll a, b; cin >> a >> b; a--; b--;
      |                         ^
a.cc:47:30: error: 'b' was not declared in this scope
   47 |         ll a, b; cin >> a >> b; a--; b--;
      |                              ^
a.cc:51:8: error: 'dfs' cannot be used as a function
   51 |     dfs(0, -1);
      |     ~~~^~~~~~~
a.cc:54:5: error: 'dfs2' was not declared in this scope; did you mean 'dfs'?
   54 |     dfs2(0);
      |     ^~~~
      |     dfs
a.cc:56:32: error: 'cout' was not declared in this scope
   56 |     for(int i = 0; i < N; i++) cout << (DP[i]*DP2[i])%M << endl;
      |                                ^~~~
a.cc:56:60: error: 'endl' was not declared in this scope
   56 |     for(int i = 0; i < N; i++) cout << (DP[i]*DP2[i])%M << endl;
      |                                                            ^~~~