criyle/codenet-compile-errors huggingface dataset:
Language: C++

#define taskname ""

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
#define long long long

const int N = 16 + 10;
const int MOD = 1e9 + 7;

int n, a[N][N], mark[1 << N];
long dp[1 << N];

inline bit(int i, int mask) {return (mask >> i) & 1;}
void cre_dp()
{
    for (int mask = 1; mask < (1 << n); ++mask) {
        for (int i = 0; i < n; ++i) if (bit(i, mask))
            for (int j = i + 1; j < n; ++j) if (bit(j, mask))
                dp[mask] += a[i][j];
    }
}

long get(int mask)
{
    if (mark[mask]) return dp[mask];

    vector<int> pos;
    for (int i = 0; i < n; ++i) if (bit(i, mask)) pos.push_back(i);
    int num = pos.size();

    for (int i = 1; i < (1 << num) - 1; ++i) {
        int cnt = 0;
        for (int j = 0; j < num; ++j) if (bit(j, i)) cnt += 1 << pos[j];
        dp[mask] = max(dp[mask], get(cnt) + get(mask ^ cnt));
    }

    mark[mask] = 1;
    return dp[mask];
}

int main()
{
//    freopen(taskname".INP", "r", stdin);
//    freopen(taskname".OUT", "w", stdout);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) cin >> a[i][j];
    cre_dp();
    cout << get((1 << n) - 1);

    return 0;
}


Compiler output:
a.cc:16:8: error: ISO C++ forbids declaration of 'bit' with no type [-fpermissive]
   16 | inline bit(int i, int mask) {return (mask >> i) & 1;}
      |        ^~~
Language: C++

#define taskname ""

#include <iostream>
#include <algorithm>

using namespace std;
#define long long long

const int N = 16 + 10;
const int MOD = 1e9 + 7;

int n, a[N][N], mark[1 << N];
long dp[1 << N];

inline bit(int i, int mask) {return (mask >> i) & 1;}
void cre_dp()
{
    for (int mask = 1; mask < (1 << n); ++mask) {
        for (int i = 0; i < n; ++i) if (bit(i, mask))
            for (int j = i + 1; j < n; ++j) if (bit(j, mask))
                dp[mask] += a[i][j];
    }
}

long get(int mask)
{
    if (mark[mask]) return dp[mask];

    vector<int> pos;
    for (int i = 0; i < n; ++i) if (bit(i, mask)) pos.push_back(i);
    int num = pos.size();

    for (int i = 1; i < (1 << num) - 1; ++i) {
        int cnt = 0;
        for (int j = 0; j < num; ++j) if (bit(j, i)) cnt += 1 << pos[j];
        dp[mask] = max(dp[mask], get(cnt) + get(mask ^ cnt));
    }

    mark[mask] = 1;
    return dp[mask];
}

int main()
{
//    freopen(taskname".INP", "r", stdin);
//    freopen(taskname".OUT", "w", stdout);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) cin >> a[i][j];
    cre_dp();
    cout << get((1 << n) - 1);

    return 0;
}


Compiler output:
a.cc:15:8: error: ISO C++ forbids declaration of 'bit' with no type [-fpermissive]
   15 | inline bit(int i, int mask) {return (mask >> i) & 1;}
      |        ^~~
a.cc: In function 'long long int get(int)':
a.cc:29:5: error: 'vector' was not declared in this scope
   29 |     vector<int> pos;
      |     ^~~~~~
a.cc:5:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    4 | #include <algorithm>
  +++ |+#include <vector>
    5 | 
a.cc:29:12: error: expected primary-expression before 'int'
   29 |     vector<int> pos;
      |            ^~~
a.cc:30:51: error: 'pos' was not declared in this scope
   30 |     for (int i = 0; i < n; ++i) if (bit(i, mask)) pos.push_back(i);
      |                                                   ^~~
a.cc:31:15: error: 'pos' was not declared in this scope
   31 |     int num = pos.size();
      |               ^~~
Language: C++

#define taskname ""

#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
#define long long long

const int N = 20 + 3;

int n, a[N][N];
long dp[1 << N];
unordered_map<int, long> dis;
typedef pair<int, long> pii;

inline bool check(int i, int j) {return __builtin_popcount(i ^ j) == (__builtin_popcount(i) + __builtin_popcount(j));}

int bit(int i, int mask) {return (mask >> i) & 1;}
int main()
{
//    freopen(taskname".INP", "r", stdin);
//    freopen(taskname".OUT", "w", stdout);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) cin >> a[i][j];

    for (int mask = 1; mask < (1 << n); ++mask) {
        for (int i = 0; i < n; ++i) if (bit(i, mask))
            for (int j = i + 1; j < n; ++j) if (bit(j, mask))
                dp[mask] += a[i + 1][j + 1];
    }

    for (int i = 1; i < (1 << n); ++i) {
        vector<pii> bonus;
        dis[i] = dp[i];

        for (pii cur : dis)
            if (check(i, cur.first)) {
                int nxt = i ^ cur.first;
                bonus.push_back({nxt, cur.second + dp[i]});
            }

        for (pii cur : bonus) dis[cur.first] = max(dis[cur.first], cur.second);
    }

    cout << dis[(1 << n) - 1];
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:37:9: error: 'vector' was not declared in this scope
   37 |         vector<pii> bonus;
      |         ^~~~~~
a.cc:6:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    5 | #include <unordered_map>
  +++ |+#include <vector>
    6 | 
a.cc:37:19: error: expected primary-expression before '>' token
   37 |         vector<pii> bonus;
      |                   ^
a.cc:37:21: error: 'bonus' was not declared in this scope
   37 |         vector<pii> bonus;
      |                     ^~~~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 16;

int matrix[MAXN + 7][MAXN + 7];

vector<int> masks_by_size[MAXN + 7];
int N;

void precalc () {
	for (int mask = 1; mask < (1 << N); mask++) {
		masks_by_size[__builtin_popcount(mask)].push_back(mask);

		for (int i = 1; i <= N; i++) {
			if (checkbit(mask, i) == true) {
				for (int j = i + 1; j <= N; j++) {
					if (checkbit(mask, j) == true) {
						cost[mask] += matrix[i][j];
					}
				}
			}
		}
	}
}

int dpf (int mask) {
	int &d = dp[mask];

	if (d != -1) {
		return d;
	}

	if (mask == (1 << N) - 1) {
		return d = 0;
	}

	d = 0;

	for (int bit_cnt = 0; bit_cnt <= N / 2; bit_cnt++) {
		for (int mask2 : masks_by_size[bit_cnt]) {
			if ((mask & mask2) == 0) {
				d = max(d, cost[mask2] + dpf(mask | mask2));
			}
		}
	}

	d = max(d, cost[mask]);

	return d;
}

int main () {
	precalc();

	cin >> N;

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			cin >> matrix[i][j];
		}
	}

	cout << dpf(0) << "\n";

	return 0;
}

Compiler output:
a.cc: In function 'void precalc()':
a.cc:17:29: error: 'checkbit' was not declared in this scope
   17 |                         if (checkbit(mask, i) == true) {
      |                             ^~~~~~~~
a.cc:20:49: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   20 |                                                 cost[mask] += matrix[i][j];
      |                                                 ^~~~
      |                                                 cosl
a.cc: In function 'int dpf(int)':
a.cc:29:18: error: 'dp' was not declared in this scope; did you mean 'd'?
   29 |         int &d = dp[mask];
      |                  ^~
      |                  d
a.cc:44:44: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   44 |                                 d = max(d, cost[mask2] + dpf(mask | mask2));
      |                                            ^~~~
      |                                            cosl
a.cc:49:20: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   49 |         d = max(d, cost[mask]);
      |                    ^~~~
      |                    cosl
Language: C++

#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
int cmp3(T lhs, T rhs) { return (lhs == rhs) ? 0 : (lhs > rhs) ? 1 : -1; }

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

lli memoized(vector<lli> &memo, vector<lli> const &scores, int s) {
  if (s == 0) { return 0; }
  if (memo[s] >= 0) { return memo[s]; }

  lli ans = scores[s];
  for (int t = (-s) & s; t != s ; t = (t - s) & s) {
    auto const u = s & ~t;
    auto const car = memoized(memo, scores, t);
    auto const cdr = memoized(memo, scores, u);
    chmax(ans, car + cdr);
  }
  memo[s] = ans;
  return ans;
}

void solve(int N, vector<vector<lli>> const &As) {
  vector<lli> scores(1<<N, 0);
  REP(s, 1 << N) {
    lli score = 0;
    bitset<32> S = s;
    REP(i, N) FOR(j, i, N-1) {
      if (S[i] && S[j]) { score += As[i][j]; }
    }
    scores[s] = score;
  }
  vector<lli> memo(1 << N, -1);
  lli ans = memoized(memo, scores, (1<<N)-1);
  cout << ans << endl;
}

int main() {
  int N;
  cin >> N;
  vector<vector<lli>> As(N, vector<lli>(N));
  REP(r, N) REP(c, N) {
    cin >> As[r][c];
  }
  solve(N, As);
  return 0;
}


Compiler output:
a.cc: In function 'void solve(int, const std::vector<std::vector<long long int> >&)':
a.cc:80:5: error: 'bitset' was not declared in this scope
   80 |     bitset<32> S = s;
      |     ^~~~~~
a.cc:15:1: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
   14 | #include <utility>
  +++ |+#include <bitset>
   15 | #include <vector>
a.cc:80:16: error: 'S' was not declared in this scope
   80 |     bitset<32> S = s;
      |                ^
Language: C++

#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;

using ll = long long;
bool isset(int mask , int i)
{
  return (mask & (1 << i));
}

const ll inf = 1e18;

ll groupCost(const vector<vector<ll>>& vec, int mask)
{
  ll ret = 0;
  int n = vec.size();
  for (int i = 0; i < n; ++i)
  {
    if (!isset(mask, i)) continue;
    for (int j = i + 1; j < n; ++j)
    {
      if (isset(mask, j))
        ret += vec[i][j];
    }
  }
  return ret;
}

#define DB2(x, y) cout << #x << ' ' << x << '|' << #y << ' ' << y << '\n'

string toBinary(int n)
{
  string s;
  while (n)
  {
    if (n & 1)
     s += '1';
   else
    s += '0';
   n >>= 1;
  }
 reverse(s.begin(), s.end());
 return s;
}


int main()
{
  int n;
  cin >> n;
  vector<vector<ll>> a(n, vector<ll>(n));
  for (int i = 0; i < n; ++i ) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }

  vector<ll> cost(1 << n), dp(1 << n, -inf);
  dp[0] = 0;

  for (int mask = 0; mask < (1 << n) ; ++mask) {
    cost[mask] = groupCost(a, mask);
   // DB2(toBinary(mask), cost[mask]);
  }

  vector<int> not_included;

  for (int mask = 0; mask < (1<<n); ++mask)
  {
    not_included.clear();
    for (int i = 0; i < n; ++i) {
      if (!isset(mask,i))
        not_included.push_back(i);
    }

    int ss = not_included.size();
    for (int mask2 = 0 ; mask2 < (1 << ss); ++mask2) {
      int x = 0;
      for (int i = 0; i < ss; ++i) {
        if (isset(mask2, i))
          x |= (1 << not_included[i]);
      }
      ll points = cost[x];
      dp[mask | x] = max(dp[mask | x], (points + dp[mask]));
    }
  }
  cout << dp[(1 << n) - 1] << '\n';


  return 0;
}


Compiler output:
a.cc: In function 'std::string toBinary(int)':
a.cc:43:2: error: 'reverse' was not declared in this scope
   43 |  reverse(s.begin(), s.end());
      |  ^~~~~~~
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
using ll = long long;

int N;
int a[16][16];
ll memo[(1<<16)]; // memo[S] := score when usagi in S are grouped
ll dp[(1<<16)];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> N;
    REP(i,N) REP(j,N) cin >> a[i][j];

    // preprocess
    REP(bit,(1<<N)){
        REP(i,N){
            rep(j,i+1,N){
                if(bit&(1<<i) && bit&(1<<j)) memo[bit] += a[i][j];
            }
        }
    }
  
    // calc max score
    REP(bit,(1<<N)){
        for(int i=bit; i; i=(i-1)&bit){ // search all subset of bit
            dp[bit] = max(dp[bit], memo[i] + dp[bit^i]);
        }
    }
    cout << dp[(1<<N)-1] << '\n';
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:17: error: 'j' was not declared in this scope
   21 |             rep(j,i+1,N){
      |                 ^
a.cc:21:13: error: 'rep' was not declared in this scope
   21 |             rep(j,i+1,N){
      |             ^~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int,int> pi;
typedef vector<int> vi;
#define ST first
#define ND second
#define PB push_back
#define DET(a,b,c) (LL(b.x-a.x)*LL((c.y-a.y))-LL((c.x-a.x))*LL((b.y-a.y)))

const LL INF = (LL)1000*1000*1000*1000*1000*1000;
int n;
int com[16][16];
LL dp[(1<<16)];
LL sum[(1<<16)];

void rec(int nr,vi&Rabbits,int mask,int score,int mask2) {
    if(nr==Rabbits.size()) {
        dp[mask] = max(dp[mask],(score+sum[mask2]));
        return;
    }
    rec(nr+1,Rabbits,mask,score,mask2);
    rec(nr+1,Rabbits,mask ^ (1<<Rabbits[nr]), score,mask2 ^ (1<<Rabbits[nr]));
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=0; i<n;i++) {
        for(int j=0; j<n;j++) {
            cin>>com[i][j];
        }
    }
    for(int mask = 0; mask<(1<<n);mask++) {
        for(int i=0; i<n;i++) {
            if(mask&(1<<i)) {
                for(int j = i+1; j<n;j++) {
                    if(mask&(1<<j)) {
                        sum[mask] = (sum[mask]+com[i][j]);
                    }
                }
            }
        }
        //cout<<mask<<" "<<sum[mask]<<"\n";
    }
    for(mask=1; mask<(1<<n); mask++) dp[mask] = -INF;
    dp[0]=0;
    for(int mask=0; mask<(1<<n); mask++) {
        vi getRabbit;
        for(int i=0; i<n;i++) {
            if(!(mask&(1<<i))) {
                getRabbit.PB(i);
            }
        }
        rec(0,getRabbit,mask,dp[mask],0);
    }
    cout<<dp[(1<<n)-1];
}


Compiler output:
a.cc: In function 'int main()':
a.cc:49:9: error: 'mask' was not declared in this scope; did you mean 'std::filesystem::perms::mask'?
   49 |     for(mask=1; mask<(1<<n); mask++) dp[mask] = -INF;
      |         ^~~~
      |         std::filesystem::perms::mask
In file included from /usr/include/c++/14/filesystem:51,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:200,
                 from a.cc:1:
/usr/include/c++/14/bits/fs_fwd.h:162:7: note: 'std::filesystem::perms::mask' declared here
  162 |       mask              = 07777,
      |       ^~~~
Language: C++

#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct edge
{
	long long to; long long len;
	bool operator<(const edge& rhs) const {
		return len > rhs.len;
	}
};

ll const MAX = BIT(22);
ll dp[MAX] = {};
ll dp2[MAX] = {};
ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
	return (x + y) % MOD;
}
ll mod_m(ll x, ll y) {
	return x * y%MOD;
}


ll bitcnt(ll x) {
	ll ans = 0;
	while (x > 0) {
		ans += (x & 1);
		x >>= 1;
	}
	return ans;
}

ll a[20][20];
	ll n;

ll f(ll bit) {
	ll v = (-bit) & bit;
	ll cnt = dp2[bit - v];
	ll j;
	REP(i, 0, n - 1) {
		if (v < BIT(i) && (BIT(i)&bit)>0) {
			cnt += a[i][j];
		}
		else if (v == BIT(i)) {
			j = i;
		}
	}
	dp2[bit] = cnt;
	return cnt;
}

int main() {
	ll x = 1;
	REP(i, 1, 16) {
		x *= 3;
	}
	cout << x << endl;
	cout << pow(3, 16) * 16 << endl;
	cin >> n;
	REP(i, 0, n - 1) {
		REP(j, 0, n - 1) {
			cin >> a[i][j];		
		}
	}
	ll t = BIT(n) - 1;

	REP(bit, 1, t) {
		ll r = bitcnt(bit);
		if (r == 1) {
			continue;
		}
		/*
		REP(i, 0, n - 1) {
			REP(j, i + 1, n - 1) {
				if (((bit&BIT(i))>0) && ((bit&BIT(j))>0)) {
					//cnt = mod_p(cnt, a[i][j]);
					//cnt = (cnt + a[i][j]) % MOD;
					cnt += a[i][j];
				}
			}
		}
		*/
		ll cnt = max(ll(0), f(bit));
		/*
		REP(bit2, 1, s - 1) {
			ll subbit = 0;
			ll v = 0;
			REP(j, 0, n - 1) {
				if (bit & BIT(j)) {
					if (BIT(v) & bit2) {
						subbit += BIT(j);
					}
					v++;
				}
			}
			ll prebit = bit - subbit;
			cnt = max(cnt, dp[subbit] + dp[prebit]);
		}
		*/
		for (ll bit2 = (bit - 1)&bit; bit2 > 0; bit2 = (bit2 - 1)&bit) {
			ll subbit = bit - bit2;
			cnt = max(cnt, dp[bit2] + dp[subbit]);
		}
		dp[bit] = cnt;
	}
	cout << dp[t] << endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:82:17: error: 'pow' was not declared in this scope
   82 |         cout << pow(3, 16) * 16 << endl;
      |                 ^~~
Language: C++

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

using mint = atcoder::modint;
int n, m;
vector<vector<int>> adj;
vector<int> par;
vector<mint> dp, ans;
mint dfs(int u = 0) {
    if (par[u] != -1) 
        adj[u].erase(find(adj[u].begin(), adj[u].end(), par[u]));
    mint s = 1;
    for (int v : adj[u]) {
        par[v] = u;
        s *= dfs(v);
    }
    return dp[u] = s + 1;
}
void dfs2(int u = 0, mint pa = 1) {
    int ch = adj[u].size();
    vector<mint> pre(ch, 1), suf(ch, 1);
    for (int i = 0; i < ch - 1; i++)
        pre[i + 1] = pre[i] * dp[adj[u][i]];
    for (int i = ch - 1; i > 0; i--)
        suf[i - 1] = suf[i] * dp[adj[u][i]];
    for (int i = 0; i < ch; i++) {
        dfs2(adj[u][i], (pa * pre[i] * suf[i]) + 1);
    }
    ans[u] = pa * (dp[u] - 1);
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin >> n >> m;
    mint::set_mod(m);
    adj.resize(n);
    par.resize(n, -1);
    dp.resize(n, 0);
    ans.resize(n, 0);
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(); // 0 as root
    dfs2();
    for (int i = 0; i < n; i++) {
        cout << ans[i].val() << '\n';
    }
    return 0;
}

Compiler output:
a.cc:1:10: fatal error: atcoder/modint: No such file or directory
    1 | #include <atcoder/modint>
      |          ^~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

struct Edge{
  int from;
  int to;
  long cost;
};

vl dp(100010,-1);
vector<vector<Edge>> Graph(100010);
vl ans(100010,-1);

long dfs(int v, int pv, long m){
  if(dp[v] != -1) return dp[v];
  dp[v] = 1;
  for(Edge ed : Graph[v]){
    int nv = ed.to;
    if(nv == pv) continue;
    dp[v] = (dp[v] * (dfs(nv, v, m) + 1)) % m;
  }
  return dp[v];
}

void dfs2(int v, int pv, long rec, long m){
  int m = Graph.at(v).size();
  vl acm(m+1,1);
  vl rev(m+1,1);
  rep(i,m){
    if(Graph.at(v).at(i).to != pv){
      acm.at(i+1) = (acm.at(i) * (dp[Graph.at(v).at(i).to]+1) ) % m;
    }else{
      acm.at(i+1) = (acm.at(i) * (rec+1)) % m;
    }
    if(Graph.at(v).at(m-1-i).to != pv){
      rev.at(m-1-i) = (rev.at(m-i) * (dp[Graph.at(v).at(m-1-i).to]+1) ) % m;
    }else{
      rev.at(m-1-i) = (rev.at(m-i) * (rec+1)) % m;
    }
  }
  ans[v] = acm[m];
  rep(i,m){
    int nv = Graph.at(v).at(i).to;
    if(nv == pv) continue;
    long r = acm[i] * rev[i+1] % m;
    dfs2(nv, v, r, m);
  }
}

int main(){
  long n,m;
  cin >> n >> m;
  rep(i,n-1){
    int x,y;
    cin >> x >> y;
    x--;y--;
    Graph.at(x).push_back({x,y,1});
    Graph.at(y).push_back({y,x,1});
  }
  ans[0] = dfs(0,-1,m);
  dfs2(0,-1,1,m);
  rep(i,n){
    cout << ans[i] << endl;
  }
}


Compiler output:
a.cc: In function 'void dfs2(int, int, long int, long int)':
a.cc:45:7: error: declaration of 'int m' shadows a parameter
   45 |   int m = Graph.at(v).size();
      |       ^
a.cc:44:41: note: 'long int m' previously declared here
   44 | void dfs2(int v, int pv, long rec, long m){
      |                                    ~~~~~^
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long
#define dp down
#define dp1 up

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 0x3f3f3f3f3f3f3f;
//const ll mod = 1e9 + 7;
const int N = 2e5 + 11;
const int NMAX = 1e4 + 11;
const ll INF64 = 3e18 + 1;
const double lil = 0.0000000000001;

//ifstream cin ("test.in");
//ofstream cout ("test.out");

int n, mod, down[N], up[N];

vector<int>v[N];


void dfs1(int nod, int p){

    ll cur = 1;

    for(auto it : v[nod]){
        if(it == p)continue;
        dfs1(it, nod);
        cur = ((cur*(down[it] + 1))%mod + mod)%mod;
    }

    down[nod] = cur;
}

void dfs2(int nod, int p){

    auto pos = find(all(v[nod]),p);
    if(pos != v[nod].end())v[nod].erase(pos);

    if(!sz(nod))return;

    vector<int>L(sz(v[nod]) + 5, 0);
    vector<int>R(sz(v[nod]) + 5, 0);

    int len = sz(v[nod]);

    L[0] = 1;
    for(int i = 1; i < len; i++){
        L[i] = ((L[i - 1]*(down[v[nod][i - 1]] + 1))%mod + mod)%mod;
    }

    R[len - 1] = 1;
    for(int i = len - 2; i >= 0; i--){
        R[i] = ((R[i + 1]*(down[v[nod][i + 1]] + 1))%mod + mod)%mod;
    }

    for(int i = 0; i < len; i++){

        int it = v[nod][i];

        up[it] = (((up[nod] + 1)*(L[i]%mod)*(R[i]%mod))%mod + mod)%mod;

        dfs2(it,nod);
    }


}

void dfs(int nd, int parent)
{
  auto I = find(v[nd].begin(), v[nd].end(), parent);
  if (I != v[nd].end()) v[nd].erase(I);

  if((int)v[nd].size() >= 1)
  {
    int n= v[nd].size();
    vector<ll> L(n, 0) , R(n, 0);
    L[0] = 1;
    R[n-1] = 1;
    for(int i=1; i<n; i++)
      L[i] = L[i-1] * (dp[v[nd][i-1]]+1) %mod;
    for(int i=n-2; i>=0; i--)
      R[i] = R[i+1] * (dp[v[nd][i+1]]+1) % mod;

    for(int i=0; i<n; i++)
    {
      int y = v[nd][i];
      dp1[y] = (dp1[nd] +1) * L[i]%mod*R[i]%mod;
      dfs(y, nd);
    }
  }
}

int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();

    cin >> n >> mod;

    for(int i = 1,x,y; i < n; i++){
        cin >> x >> y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs1(1,0);

    dfs2(1,0);

    for(int i = 1; i <= n; i++){
        cout << ((down[i]*(up[i] + 1))%mod + mod)%mod << '\n';
    }


}

Compiler output:
a.cc: In function 'void dfs2(long long int, long long int)':
a.cc:11:25: error: request for member 'size' in 'nod', which is of non-class type 'long long int'
   11 | #define sz(x) (int)((x).size())
      |                         ^~~~
a.cc:52:9: note: in expansion of macro 'sz'
   52 |     if(!sz(nod))return;
      |         ^~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e14;
const ll mod = 1e9+7;
// __uint128_t

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;



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


int dfs(Bint x, Bint p){
    Bint 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(Bint x, Bint p = -1){
    Bint res = 1;
    for(auto v : G[x]){
        if(v == p) continue;
        DP2[v] = (DP2[x]/(DP[v]+1)+1) * DP[v];
    }
    for(auto v : G[x]){
        if(p != v)dfs2(v, x);
    }
}

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

    dfs2(0);

    for(auto x : DP2) cout << x%M << endl;

}

Compiler output:
a.cc:8:10: fatal error: boost/multiprecision/cpp_dec_float.hpp: No such file or directory
    8 | #include <boost/multiprecision/cpp_dec_float.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define show(x) cout<<#x<<" "<<x<<" ";
#define f(i,j,k) for(int i = j;i<=k;i++)
#define fr(i,j,k) for(int i = j;i>=k;i--)
#define ll long long
#define all(A)  A.begin(),A.end()  
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);  
const int MSIZE = 1e5+5;
const int MOD = 1e9+7;

ll dp[MSIZE];
int par[MSIZE];

ll solve(int x,int p,int &m,vector<vector<int>>& g) {
    ll res = 1;
    par[x] = p;
    for(int y : g[x]) if(y!=p) res*=(1+solve(y,x,m,g)),res%=m;
    return dp[x] = res;
}

void update(int x,int &m,vector<vector<int>>& g) {
    if(par[x])  
        dp[x] = (dp[x] * (1+dp[par[x]]/(1+dp[x])))%m;
    for(int y : g[x]) if(y!=par[x]) fill(y,m,g);
}


int main(){

    FIO
    int n, m; cin>>n>>m;
    vector<vector<int>> g(n+1);
    f(i,1,n-1)  {
        int x, y; cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    solve(1,0,m,g);
    update(1,m,g);
    f(i,1,n)    cout<<dp[i]<<endl;
    return 0;
}
    


Compiler output:
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'typename __gnu_cxx::__enable_if<(! std::__is_scalar<_Tp>::__value), void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int; _Tp = vector<vector<int> >; typename __gnu_cxx::__enable_if<(! __is_scalar<_Tp>::__value), void>::__type = void]':
/usr/include/c++/14/bits/stl_algobase.h:998:21:   required from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = int; _Tp = vector<vector<int> >]'
  998 |     { std::__fill_a1(__first, __last, __value); }
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1029:20:   required from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int; _Tp = vector<vector<int> >]'
 1029 |       std::__fill_a(__first, __last, __value);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:27:41:   required from here
   27 |     for(int y : g[x]) if(y!=par[x]) fill(y,m,g);
      |                                     ~~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:940:9: error: invalid type argument of unary '*' (have 'int')
  940 |         *__first = __value;
      |         ^~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


map<int,vi>mp;
const int mx=1e5+5;
int m;
int dp1[mx],dp2[mx];
void dfs2(int u,int p){
   dp2[u]=0;
   for(auto c:mp[u]){
        dp2[u]=dp1[u];
      int ans=(dp2[p])/(dp1[u]+1);
      ans+=1;
      dp2[u]=(dp2[u]*ans)%m;
      if(c==p)continue;
      // if(p==0){dp2[u]==dp1[u];continue;}
    
      // cout<<p<<" ";
      dfs2(c,u);
   }
}
void dfs(int u,int p){
   dp1[u]=1;
   for(auto c:mp[u]){
      if(c==p)continue;
         dfs(c,u);
      dp1[u]=(dp1[u]*(dp1[c]+1))%m;
   }
   // dp1[u]+=1;
}
int32_t main(){
int n;cin>>n>>m;
if(n==1){cout<<1<<endl;continue;}
for(int i=1;i<n;i++){
int x,y;cin>>x>>y;
mp[x].eb(y);
mp[y].eb(x);
}
dfs(1,0);
dfs2(1,0);
for(int i=1;i<=n;i++){
   // if(!dp2[i])cout<<dp1[1]<<endl;
    cout<<dp2[i]<<endl;
}
}

Compiler output:
a.cc: In function 'int32_t main()':
a.cc:55:24: error: continue statement not within a loop
   55 | if(n==1){cout<<1<<endl;continue;}
      |                        ^~~~~~~~
Language: C++

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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll inf = (1LL << 50);

vector<int> to[200200];
map<int, map<int, int>> memo;  // key = from, to
map<int, map<int, bool>> used; // key = from, to

int mod;
int dfs(int u, int p = xx) {
    if (used[p][u]) return memo[p][u];

    used[p][u] = true;
    int ret = 1;
    for (auto v : to[u]) {
        if (v == p) continue;
        ret = (ret * (dfs(v, u) + 1)) % mod;
    }

    return memo[p][u] = ret;
}

void solve(long long N, long long M, std::vector<long long> x, std::vector<long long> y) {
    mod = M;
    rep(i, N - 1) {
        to[x[i]].push_back(y[i]);
        to[y[i]].push_back(x[i]);
    }

    rep(i, N) {
        cout << dfs(i) << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> x(N - 1);
    std::vector<long long> y(N - 1);
    for (int i = 0; i < N - 1; i++) {
        scanf("%lld", &x[i]);
        scanf("%lld", &y[i]);
        x[i]--;
        y[i]--;
    }
    solve(N, M, std::move(x), std::move(y));
    return 0;
}


Compiler output:
a.cc:36:24: error: 'xx' was not declared in this scope
   36 | int dfs(int u, int p = xx) {
      |                        ^~
Language: C++

//This code is solely the property of StarnyC
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define ld          long double
#define int         long long
#define hell        1000000007
#define hellx       998244353
#define pb          push_back
#define mp          make_pair
#define reset(a,b)  memset(a,b,sizeof(a))
#define Go_Baby_Go  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define deb(x)      cout << (#x) << " is " << (x) << endl;
#define onbits(n)    __builtin_popcount(n)
#define INF         numeric_limits<int>::max()
#define ff          first
#define ss          second
#define pii         pair<ll,ll>
#define sz(a)       (ll)((a).size())
#define all(c)      (c).begin(),(c).end()
#define forn(i,n)   for(int i=0;i<(int)n;i++)
#define endl		'\n'

ll gcd(ll a,ll b) {
	if(b==0)    return a;
	            return gcd(b,a%b);
}
 
ll binexp(ll x,ll n,ll m) {
    if(!n)          return 1;
    else if(n&1)    return (x%m)*binexp((x%m)*(x%m),n/2,m)%m;
    else if(!(n&1)) return binexp((x%m)*(x%m),n/2,m)%m;
                    return 0;
}
int ans[100005],m;
vector <int> adj[100005];
map <pii , int> dp;

int dfs(int par, int child)
{
	//cout << par << " " << child << endl;
	if( m.count(dp[ {par, child} ])  ) { 
		//cout << dp[ {par, child} ] << " calculated result  " << endl;
		return dp[ {par, child} ];
	}

	int temp = 1;
	for(auto i:adj[child]) {
		if(i==par) continue;
		else { temp *= dfs(child, i) ; temp %= m; }
	}

	temp++;
	dp[ {par, child} ] = temp;
	//cout << dp[ {par, child} ] << " first time calculating " << endl;
	return temp%m;
}

int32_t solve(ll _,ll _t)
{  
	int n;
	cin >> n >> m;
	for(int i = 0; i < n-1 ; i++) {
		int x , y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}


	for(int i = 1; i <= n; i++) {
		ans[i] = 1;
		for(auto j:adj[i]) {
			ans[i] *= dfs(i,j);
			ans[i] %= m;
		}
		cout<<ans[i]%m<<endl;
	}

	


}
 
int32_t main()
{
 Go_Baby_Go
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" ;

ll _=1;
//cin>>_;
//cin.ignore();
ll _t=_;
while(_--)
solve(_,_t);
 
return 0;
 
}

Compiler output:
a.cc: In function 'long long int dfs(long long int, long long int)':
a.cc:42:15: error: request for member 'count' in 'm', which is of non-class type 'long long int'
   42 |         if( m.count(dp[ {par, child} ])  ) {
      |               ^~~~~
a.cc: In function 'int32_t solve(long long int, long long int)':
a.cc:83:1: warning: no return statement in function returning non-void [-Wreturn-type]
   83 | }
      | ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int up[N], down[N];
int n,m;
vector<int> g[N];
int dfs1(int u, int p){
	int ans1 = 1, ans2 = 1;
	
	for(auto v:g[u]){
		if(v!=p){
			ans1 = (ans*(1+dfs1(v,u)))%m;
		}
	}
	
	down[u] = ans1;
	return ans1;
}
int vis[N];
int tin[N], tout[N];
int timer = 0;
void dfs(int u, int p){
	tin[u] = ++timer;
	
	for(auto v:g[u]){
		if(v!=p)
			dfs(v,u);
	}
	tout[u] = ++timer;
}
bool is_ancestor(int par, int child){
	if(par == 0) return true;
	if(child == 0) return false;
	if(tin[par]<=tin[child] and tout[par]>=tout[child]) return true;
	return false;
}

int dfs2(int u, int p){
	if(vis[u]) return up[u];
	// trace(u);
	vis[u] = 1;
	int ans = 1;
	ans = (ans*up[p])%m;
	for(auto v:g[p]) if(v!=u && !is_ancestor(v,p)) ans = (ans*(1+down[v]))%m;
	// trace(u,ans,up[p],p);
	up[u] = 1+ans;
	for(auto v:g[u]) if(v!=p) dfs2(v,u);
	return 1+ans;
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		cin >> n >> m;
		rep(i,0,n-1){
			int a,b;
			cin >> a >> b;
			g[a].pb(b);
			g[b].pb(a);
		}
		dfs(1,0);
		dfs1(1,0);
		dfs2(1,0);
		rep(i,1,n+1) cout<<(up[i]*down[i])%m<<endl;
	}
}


Compiler output:
a.cc: In function 'long long int dfs1(long long int, long long int)':
a.cc:35:33: error: 'ans' was not declared in this scope; did you mean 'ans2'?
   35 |                         ans1 = (ans*(1+dfs1(v,u)))%m;
      |                                 ^~~
      |                                 ans2
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int up[N], down[N];
int n,m;
vector<int> g[N];
int dfs1(int u, int p){
	int ans1 = 1, ans2 = 1;
	
	for(auto v:g[u]){
		if(v!=p){
			ans1 = (ans*(1+dfs(v,u)))%m;
		}
	}
	
	down[u] = ans1;
	return ans1;
}
int vis[N];
int tin[N], tout[N];
int timer = 0;
void dfs(int u, int p){
	tin[u] = ++timer;
	
	for(auto v:g[u]){
		if(v!=p)
			dfs(v,u);
	}
	tout[u] = ++timer;
}
bool is_ancestor(int par, int child){
	if(par == 0) return true;
	if(child == 0) return false;
	if(tin[par]<=tin[child] and tout[par]>=tout[child]) return true;
	return false;
}

int dfs2(int u, int p){
	if(vis[u]) return up[u];
	// trace(u);
	vis[u] = 1;
	int ans = 1;
	ans = (ans*up[p])%m;
	for(auto v:g[p]) if(v!=u && !is_ancestor(v,p)) ans = (ans*(1+down[v]))%m;
	// trace(u,ans,up[p],p);
	up[u] = 1+ans;
	for(auto v:g[u]) if(v!=p) dfs2(v,u);
	return 1+ans;
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		cin >> n >> m;
		rep(i,0,n-1){
			int a,b;
			cin >> a >> b;
			g[a].pb(b);
			g[b].pb(a);
		}
		dfs(1,0);
		dfs1(1,0);
		dfs2(1,0);
		rep(i,1,n+1) cout<<(up[i]*down[i])%m<<endl;
	}
}


Compiler output:
a.cc: In function 'long long int dfs1(long long int, long long int)':
a.cc:35:33: error: 'ans' was not declared in this scope; did you mean 'ans2'?
   35 |                         ans1 = (ans*(1+dfs(v,u)))%m;
      |                                 ^~~
      |                                 ans2
a.cc:35:40: error: 'dfs' was not declared in this scope; did you mean 'ffs'?
   35 |                         ans1 = (ans*(1+dfs(v,u)))%m;
      |                                        ^~~
      |                                        ffs
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int up[N], down[N];
int n,m;
vector<int> g[N];
int dfs1(int u, int p){
	int ans1 = 1, ans2 = 1;
	
	for(auto v:g[u]){
		if(v!=p){
			ans = (ans*(1+dfs(v,u)))%m;
		}
	}
	
	down[u] = ans1;
	return ans1;
}
int vis[N];
int tin[N], tout[N];
int timer = 0;
void dfs(int u, int p){
	tin[u] = ++timer;
	
	for(auto v:g[u]){
		if(v!=p)
			dfs(v,u);
	}
	tout[u] = ++timer;
}
bool is_ancestor(int par, int child){
	if(par == 0) return true;
	if(child == 0) return false;
	if(tin[par]<=tin[child] and tout[par]>=tout[child]) return true;
	return false;
}

int dfs2(int u, int p){
	if(vis[u]) return up[u];
	// trace(u);
	vis[u] = 1;
	int ans = 1;
	ans = (ans*up[p])%m;
	for(auto v:g[p]) if(v!=u && !is_ancestor(v,p)) ans = (ans*(1+down[v]))%m;
	// trace(u,ans,up[p],p);
	up[u] = 1+ans;
	for(auto v:g[u]) if(v!=p) dfs2(v,u);
	return 1+ans;
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		cin >> n >> m;
		rep(i,0,n-1){
			int a,b;
			cin >> a >> b;
			g[a].pb(b);
			g[b].pb(a);
		}
		dfs(1,0);
		dfs1(1,0);
		dfs2(1,0);
		rep(i,1,n+1) cout<<(up[i]*down[i])%m<<endl;
	}
}


Compiler output:
a.cc: In function 'long long int dfs1(long long int, long long int)':
a.cc:35:25: error: 'ans' was not declared in this scope; did you mean 'ans2'?
   35 |                         ans = (ans*(1+dfs(v,u)))%m;
      |                         ^~~
      |                         ans2
a.cc:35:39: error: 'dfs' was not declared in this scope; did you mean 'ffs'?
   35 |                         ans = (ans*(1+dfs(v,u)))%m;
      |                                       ^~~
      |                                       ffs
Language: C++

    #include <cstdio>
    #include <vector>
    #include <map>
    #include <utility>
    #include <cstring>
    using namespace std;
    typedef pair<int,int> ii;
    int n,m;
    vector<ii> edges;
    vector<int> al[100005];
    ll memo[200005];
    int dfs(int i){ ///j=0 not coloured, j=1 is coloured
        if (memo[i]!=-1) return memo[i];
        long long ans=1;
        for (vector<int>::iterator it=al[edges[i].second].begin();it!=al[edges[i].second].end();it++){
            if (edges[i].first==edges[*it].second) continue;
            ans=(ans*(dfs(*it)+1))%m;
        }
        return memo[i]=ans;
    }
    int main(){
      memset(memo,-1,sizeof(memo));
        scanf("%d%d",&n,&m);
        int a,b;
        int counter=0;
        for (int x=1;x<n;x++){
            scanf("%d%d",&a,&b);
            edges.push_back(ii(a,b));
            al[a].push_back(counter++);
            edges.push_back(ii(b,a));
            al[b].push_back(counter++);
        }
     
        long long ans;
        for (int x=1;x<=n;x++){
            ans=1;
            for (vector<int>::iterator it=al[x].begin();it!=al[x].end();it++){
                ans=(ans*(dfs(*it)+1))%m;
            }
            printf("%lld\n",ans);
        }
    }

Compiler output:
a.cc:11:5: error: 'll' does not name a type
   11 |     ll memo[200005];
      |     ^~
a.cc: In function 'int dfs(int)':
a.cc:13:13: error: 'memo' was not declared in this scope
   13 |         if (memo[i]!=-1) return memo[i];
      |             ^~~~
a.cc:19:16: error: 'memo' was not declared in this scope
   19 |         return memo[i]=ans;
      |                ^~~~
a.cc: In function 'int main()':
a.cc:22:14: error: 'memo' was not declared in this scope
   22 |       memset(memo,-1,sizeof(memo));
      |              ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
// DON'T USE THESE MACROS DURING ICPC PRACTICE
#define For(i,n) for (int i=0; i<n; i++)
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define Down(i,n) for (int i=n-1; i>=0; i--)
#define DOWN(i,a,b) for (int i=b; i>=a; i--)
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef complex<ld> pt;
typedef vector<pt> pol;
typedef vector<int> vi;
 
const char nl = '\n';
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9+7;
const ld EPS = 1e-10;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N = 1e5+1;
int M; // mod
vector<int> adj[N];
int par[N];
ll sub[N];

ll precompute(int u, int p) {
  par[u] = p;
  sub[u] = 1;
  for (int v : adj[u]) {
    if (v != p) {
      sub[u] = sub[u] * (1 + precompute(v, u)) % M;
    }
  }
  return sub[u];
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(10);

  int n;
  cin >> n >> M;
  For(i,n-1) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  precompute(1, 0);

  FOR(i,1,n) {
    cout << solve(i) << nl;
  }

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:66:13: error: 'solve' was not declared in this scope
   66 |     cout << solve(i) << nl;
      |             ^~~~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define INF 1000000007
#define LLINF 2696969696969696969ll
#define MAXN 100013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N;
ll MOD;
vi edge[MAXN];
ll dp[MAXN], dp1[MAXN];
//dp[x] = # of ways such that you are on

void dfs(int u, int p)
{
	for (int v : edge[u])
	{
		if (v == p) continue;
		dfs(v, u);
	}
	dp[u] = 1;
	for (int v : edge[u])
	{
		if (v == p) continue;
		dp[u] *= (dp[v] + 1); dp[u] %= MOD;
	}
	// cerr << u << ' ' << dp[u][0] << ' '  << dp[u][1] << endl;
}
void dfs1(int u, int p)
{
	vl pref(SZ(edge[u]) + 1), suf(SZ(edge[u]) + 1);
	pref[0] = 1;
	FOR(i, 0, SZ(edge[u]))
	{
		int v = edge[u][i];
		if (v == p)
		{
			pref[i + 1] = pref[i];
			continue;
		}
		pref[i + 1] = pref[i] * (dp[v] + 1); pref[i + 1] %= MOD;
	}
	suf[SZ(edge[u])] = 1;
	FORD(i, SZ(edge[u]), 0)
	{
		int v = edge[u][i];
		if (v == p)
		{
			suf[i] = suf[i + 1];
			continue;
		}
		suf[i] = suf[i + 1] * (dp[v] + 1); suf[i] %= MOD:
	}
	FOR(i, 0, SZ(edge[u]))
	{
		int v = edge[u][i];
		if (v == p) continue;
		dp1[v] = pref[i] * suf[i + 1] % MOD * (dp1[u] + 1) % MOD;
	}
	for (int v : edge[u])
	{
		if (v == p) continue;
		dfs1(v, u);
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> MOD;
	FOR(i, 0, N - 1)
	{
		int u, v; cin >> u >> v; u--; v--;
		edge[u].PB(v);
		edge[v].PB(u);
	}
	dfs(0, N);
	dfs1(0, N);
	cout << dp[0] << '\n';
	FOR(i, 1, N)
	{
		cout << dp[i] * (dp1[i] + 1) % MOD << '\n';
	}
	return 0;
}


Compiler output:
a.cc: In function 'void dfs1(int, int)':
a.cc:83:65: error: expected ';' before ':' token
   83 |                 suf[i] = suf[i + 1] * (dp[v] + 1); suf[i] %= MOD:
      |                                                                 ^
      |                                                                 ;