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

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define cps CLOCKS_PER_SEC
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// struct chash { int operator()(int x) const { return x ^ RANDOM; }};
// cc_hash_table<int, int, hash<int>> cnt;

const int MAXN = 2e5 + 10;
vector<int> graph[MAXN];
int c[MAXN];
int cnt[MAXN],subsum[MAXN];

void dfs(int u,int p){
    subsum[u] = 1;
    for(int v:graph[u]){
        if(v == p) continue;
        dfs(v,u);
        subsum[u] += subsum[v];
    }
}

int soln[MAXN];

void dfs_solve(int u,int p){
    int n = cnt[c[u]];
    int t_add = subsum[u]*(n-subsum[u]+1),sum = 0;

    for(int v:graph[u]){
        if(v == p) continue;
        t_add += sum*subsum[v];
        sum += subsum[v];
    }

    soln[c[u]] += t_add;

    for(int v:graph[u]){
        if(v == p) continue;
        cnt[c[u]] = subsum[v];
        dfs_solve(v,u); 
    }    

    val[c[u]] = n - subsum[u];
}

void solve(){
    int n; cin>>n;

    FOR(i,1,n) {cin>>c[i]; cnt[i] = n;}
    FOR(i,1,n-1){
        int u,v; cin>>u>>v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dfs(1,0);
    dfs_solve(1,0);

    FOR(i,1,n) cout<<soln[i]<<endl;
}
 
signed main(){
 
    FastRead; 


    int t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Compiler output:
a.cc: In function 'void dfs_solve(long long int, long long int)':
a.cc:70:5: error: 'val' was not declared in this scope
   70 |     val[c[u]] = n - subsum[u];
      |     ^~~
Language: C

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5;
int sz[N], c[N], lst[N], h[N];
long long ans[N], f[N], val[N], s[N];
vector <int> g[N];

void dfs(int v, int p = 0) {
    int prv = lst[c[v]];
    for (int u : g[v]) if (u != p) lst[c[v]] = u, dfs(u, v), ans[c[v]] += 1ll * sz[v] * sz[u], sz[v] += sz[u];
    lst[c[v]] = prv, sz[v]++;
    if (prv > 1) val[prv] += sz[v];
    else s[c[v]] += sz[v];
    return ;
}
void Solve(int v, int p = 0) {
    int prv = lst[c[v]];
    ans[c[v]] += 1ll * sz[v] * (sz[prv] - sz[v] + 1);
    if (prv > 1) f[c[v]] += 1ll * sz[v] * (val[prv] - sz[v]);
    else f[c[v]] += 1ll * sz[v] * (s[c[v]] - sz[v]);
    for (int u : g[v]) if (u != p) lst[c[v]] = u, Solve(u, v);
    lst[c[v]] = prv;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin >> n;
    for (int i = 1; i <= n; i++) cin >> c[i];
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v), g[v].push_back(u);
    }
    fill(lst, lst + N, 1), dfs(1), fill(lst, lst + N, 1), Solve(1);
    for (int i = 1; i <= n; i++) cout << ans[i] - (f[i]/2) << "\n";


    return 0;
}


Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    UL N;
    vector<UL> C;
    vector<vector<UL>> E;
    vector<UL> Sz, P, A, I, CN;
    vector<ULL> ans;

    void DFS(UL p) {
        I[p] = CN[C[p]];
        for (UL e : E[p]) {
            if (P[p] == e) continue;
            P[e] = p;
            DFS(e);

            ULL t = Sz[e] - (A[C[p]] - I[p]);
            ans[C[p]] += t * (t + 1) / 2;
            I[p] += Sz[e];
            A[C[p]] = I[p];
        }
        A[C[p]]++;
        if (p != 0) Sz[P[p]] += Sz[p];
    }

    void Solve() {
        cin >> N;
        C.resize(N); rep(i, N) { cin >> C[i]; C[i]--; }
        E.resize(N);
        rep(i, N - 1) {
            UL u, v; cin >> u >> v; u--; v--;
            E[u].push_back(v);
            E[v].push_back(u);
        }
        Sz.assign(N, 1);
        P.assign(N, -1);
        A.assign(N, 0);
        I.assign(N, 0);
        CN.assign(N, 0);
        ans.assign(N, 0);

        DFS(0);

        rep(i, N) {
            ULL t = N - A[i];
            ans[i] += t * (t + 1) / 2;
            ans[i] = (ULL)N * (N + 1) / 2 - ans[i];
            cout << ans[i] << endl;
        }
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}


Compiler output:
main.c:1:9: fatal error: bits/stdc++.h: No such file or directory
    1 | #include<bits/stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 2e3 + 5;

int n,a[N],d[N];
ll dp[N][N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){cin>>a[i];d[i]=i;}
	sort(d+1,d+1+n,[&](int x,int y){return a[x]>a[y];});
	for(int i=0;i<=n;i++){
		for(int j=0;i+j<=n;j++){
			int k=i+j;
			dp[i][j]=max(d[i][j], dp[i-1][j]+a[d[k]]*abs(d[k]-i));
			dp[i][j]=max(d[i][j], dp[i][j-1]+a[d[k]]*abs(n-(j-1)-d[k]));
		}
	}
	ll ans=0;
	for(int i=0;i<=n;i++) ans=max(ans,dp[i][n-i]);
	cout<<ans;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:42: error: invalid types 'int[int]' for array subscript
   24 |                         dp[i][j]=max(d[i][j], dp[i-1][j]+a[d[k]]*abs(d[k]-i));
      |                                          ^
a.cc:25:42: error: invalid types 'int[int]' for array subscript
   25 |                         dp[i][j]=max(d[i][j], dp[i][j-1]+a[d[k]]*abs(n-(j-1)-d[k]));
      |                                          ^
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


vector<vector<long long> > g;
vector<long long> a;
vector<char> used;
vector<long long> ans;

long long dfs(long long v){
  used[v] = true;
  ans[a[v]]++;
  long long c = 0;
  for(int i: g[v]){
    if(!used[i]){
      c += dfs(i);
    }
  }
  ans[a[v]] += c;
  return c + 1;
}


int main() {
  long long n;
  cin >> n;
  a.resize(n + 1);
  for(int i = 1; i <= n; ++i) cin >> a[i];
  g.resize(n + 1, vector<long long>(n + 1));
  long long fr, to;
  for(int i = 0; i < n - 1; ++i){
    cin >> fr >> to;
    g[fr].push_back(to);
    g[to].push_back(fr);
  }
  ans.resize(n + 1);
  used.assign(n + 1, false);
  dfs(i);
  for(int i = 1; i <= n; ++i) cout << ans[i] / 2 << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:52:7: error: 'i' was not declared in this scope
   52 |   dfs(i);
      |       ^
Language: C

#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


vector<vector<long long> > g;
vector<long long> a;
vector<char> used;
vector<long long> ans;

long long dfs(long long v){
  used[v] = true;
  ans[a[v]]++;
  long long c = 0;
  for(int i: g[v]){
    if(!used[i]){
      c += dfs(i);
    }
  }
  ans[a[v]] += c;
  return c + 1;
}


int main() {
  long long n;
  cin >> n;
  a.resize(n + 1);
  for(int i = 1; i <= n; ++i) cin >> a[i];
  g.resize(n + 1, vector<long long>(n + 1));
  long long fr, to;
  for(int i = 0; i < n - 1; ++i){
    cin >> fr >> to;
    g[fr].push_back(to);
    g[to].push_back(fr);
  }
  ans.resize(n + 1);
  for(int i = 1; i <= n; ++i){
    used.assign(n + 1, false);
    dfs(i);
  }
  for(int i = 1; i <= n; ++i) cout << ans[i] / 2 << endl;
}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C

#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define rep(i, n) rep2(i, 0, n)
using ll = long long;
using V = vector<int>;
using Vll = vector<ll>;
using VV = vector<V>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

VV G;
V c, dp;
Vll ans;
int s = 0;

ll chs(ll x) {
  return x*(x+1)/2;
}

void dfs(int u, int p=-1) {
  int tmp = s + dp[c[u]];
  ++s;
  for (auto v : G[u]) if (v != p) {
    dp[c[u]] = -s;
    dfs(v, u);
    ans[c[u]] -= chs(s + dp[c[u]]);
  }
  dp[c[u]] = tmp - s;
}

int main() {
  ll n; cin >> n;
  G.assign(n, V());
  c.assign(n, 0);
  dp.assign(n, 0);
  ans.assign(n, n*(n+1)/2);

  rep(i, n) {
    cin >> c[i];
    --c[i];
  }
  rep(i, n-1) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs(0);
  rep(i, n) {
    ans[i] -= chs(s + dp[i]);
    cout << ans[i] << endl;
  }
  return 0;
}


Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

#include <bits/stdc++.h>
using namespace std;
vector <int> c;
vector <vector <int>> g;
vector <bool> clr,used;


int dfs(int v, int color)
{
    //cout << "_";

    used[v] = true;
    int sum = 1;
    for (auto x:g[v])
        {
            if (!used[x] && c[x]!=color)
                sum+= dfs(x,color);
        }
    return sum;
}



int main()
{

int n;
cin >> n;
c.resize(n);
g.resize(n);
clr.resize(n+1);
used.resize(n);
//int now;
for (int i=0; i<n; i++) {cin >> c[i];}

for (int i=1; i<n; i++)
{
    int a,b;
    cin >> a >> b; a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
}
//cout << "1";

for (int j=1; j<=n; j++)
{
    for (int i=0; i<n; i++) used[i] = false;

    long int sum = 0;
    for (int i=0; i<n; i++)
        {
            //cout << "1";
            if (c[i]!=j && !used[i])
                {int now =  dfs(i,j);
                 sum +=  now * (now+1)/2;
                }
        }

    cout << n*(n+1)/2 - sum << "\n";
}







}








Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

vector<int> to[200005];
int c[200005];
int buka[200005];
vector<int> data[200005];
int numcol[200005];

void dfs(int x, int p) {
    if (to[x].size()==1 && to[x][0]==p) return;
    for (int e: to[x]) {
        if (e==p) continue;
        dfs(e, x);
        buka[x] += (buka[e])+1;
    }
}

void dfs2(int x, int p) {
    int color = c[x];
    if (data[color].size()) {
        data[color][data[color].size()-1] -= (buka[x]+1);
    }
    int id = data[color].size()-1;
    for (int e: to[x]) {
        if (e==p) continue;
        data[color].push_back(buka[e]+1);
        //int v = data[color][id];
        //data[color].erase(data[color].begin()+id);
        //data[color].push_back(v);
        //id = data[color].size()-1;
        dfs2(e, x);
    }
}

int main(){
    int n;
    cin >> n;
    
    
    rep(i, n) {
        cin >> c[i];
        c[i]--;
        numcol[c[i]]++;
    }
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].emplace_back(b);
        to[b].emplace_back(a);
    }

    dfs(0, -1);
    dfs2(0, -1);

    rep(i, n) {
        /*
        rep(j, data[i].size()) {
            cout << data[i][j] << " ";
        }
        */
        //cout << endl;
        if (data[i].size()==0 && numcol[i]==0) {
            //ll ans2 = numcol[i]*(numcol[i]+1)/2;
            cout << "0" << endl;
            continue;
        }
        ll sum = 0;
        ll ans = 0;
        for (int e: data[i]) {
            ll x = e;
            sum += x;
            ans += x*(x+1)/2;
        }
        ll rem = n - sum - numcol[i];
        ans += rem*(rem+1)/2;
        ll res = n*(n+1)/2 - ans;
        cout << res << endl;
    }

    
    
    
    
    return 0;
}


Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

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

#define max_N 200010

int k;
vector<int> edges[max_N];
vector<int> color_vertex[max_N];

int in[max_N];
int out[max_N];

long comb2(int x){
	return (long) x * (x-1) / 2 + x;
}

int sum_prefix(const int &a, const int &b){
	int sum = 0;
	for(int i = a; i < b; i++)
		sum += prefix[i];
	return sum;
}

void dfs(int v, int p = -1){
	in[v] = k++;
	for(auto x: edges[v]) {
		if(x == p) continue;
		dfs(x, v);
	}
	out[v] = k;
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		int c;
		scanf("%d", &c);
		color_vertex[c-1].push_back(i);
	}
	for(int i = 0; i < n-1; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		edges[x-1].push_back(y-1);
		edges[y-1].push_back(x-1);
	}

	long total = comb2(n);
	vector<int> prefix(n, 1);

	dfs(0);
	for(int i = 0; i < n; i++) {
		long ans = total;

		sort(color_vertex[i].begin(), color_vertex[i].end(), [&](int a, int b){
			return in[a] > in[b];
		});

		vector<pair<int, int> > history;
		for(auto v: color_vertex[i]) {
			int vsub_size = 1;
			for(auto u: edges[v]) {
				if(in[u] < in[v]) continue;
				int usub_size = sum_prefix(in[u], out[u]);
				ans -= comb2(usub_size);
				vsub_size += usub_size;
			}
			prefix[in[v]] -= vsub_size;
			history.emplace_back(in[v], vsub_size);
		}
		ans -= comb2(sum_prefix(0, n));

		for(auto p: history)
			prefix[p.first] += p.second;

		printf("%ld\n", ans);
	}
}


Compiler output:
a.cc: In function 'int sum_prefix(const int&, const int&)':
a.cc:20:24: error: 'prefix' was not declared in this scope; did you mean 'profil'?
   20 |                 sum += prefix[i];
      |                        ^~~~~~
      |                        profil
Language: C

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
const long long MAXN = 5e3+5;
long long n;
vector<long long> v1[MAXN];
long long ans[MAXN];
long long res[MAXN];
long long col[MAXN];

long long sz[MAXN];
long long f(long long x){
    return 1LL*x*(x+1)/2;
}
void dfs(long long curr, long long par){
    long long tmp = res[col[curr]];
    for(long long x:v1[curr]){
        if(x!=par){
            res[col[curr]] = 0;
            dfs(x,curr);
            sz[curr] += sz[x];
            ans[col[curr]]-=f(sz[x]-res[col[curr]]);
        }
    }
    res[col[curr]] = tmp+sz[curr];
}
int main() {
    cin>>n;
    for(long long i=1;i<=n;i++){
        cin>>col[i];
        sz[i] = 1;
    }
    for(long long i=1;i<n;i++){
        long long x,y;
        cin>>x>>y;
        v1[x].push_back(y);
        v1[y].push_back(x);
    }
    dfs(1,1);
    for(long long i=1;i<=n;i++){
        //cout<<col[i]<<endl;
        cout<<(ans[i]+f(n)-f(n-res[i]))<<endl;
    }
}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<int> C(N);
    vector<vector<int>> G(N);
    REP(i,N) cin >> C[i], C[i]--;
    REP(i,N-1){
        int u, v;
        cin >> u >> v;
        G[--u].push_back(--v);
        G[v].push_back(u);
    }
    vector<vector<int>> res(N);
    vector<int> cnt(N);
    vector<map<int, int>> dp(N);
    auto dfs = [&](auto && self, int v, int par) -> void{
        for(auto nv : G[v]){
            if(nv == par) continue;
            self(self, nv, v);
            cnt[v] += cnt[nv];

            int tmpCnt = cnt[nv];
            if(dp[nv].count(C[nv])) tmpCnt -= dp[nv][C[v]];
            res[C[v]].push_back(tmpCnt);

            //merge technique
            if(dp[v].size() < dp[nv].size()) swap(dp[v], dp[nv]);
            for(auto &x : dp[nv]) dp[v][x.first] += x.second;
        }
        cnt[v]++;
        dp[v][C[v]] = cnt[v];
    };
    
    dfs(dfs, 0, -1);
    REP(i,N) res[i].push_back(N - dp[0][i]);
    vector<ll> ans(N, N * (N + 1) / 2);
    REP(i,N) for(auto c : res[i]) ans[i] -= c * (c + 1) / 2;

    REP(i,N) cout << ans[i] << endl;
}


Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

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

#define read(num) scanf("%d", &num)
#define readll(num) scanf("%lld", &num)
#define read2(num1, num2) scanf("%d%d", &num1, &num2)
#define read3(num1, num2, num3) scanf("%d%d%d", &num1, &num2, &num3)
#define reads(str) scanf("%s", str)
#define readc(ch) scanf("%c", &ch)

#define pb push_back
#define mp make_pair

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
ll color[200005],child[200005],ans[200005];
vector<ll>adj[200005];

ll n;
void dfs(int in,int vis[]){
    vis[in]=1;
    child[in]=1;
    vector<ll>kk;
    ans[color[in]]+=1;
    for(v:adj[in]){
        if(vis[v]==0){
            dfs(v,vis);
            kk.pb(child[v]);
            child[in]+=child[v];
        }
    }
    ans[color[in]]+=(n-child[in])*child[in];
    for(int i=0;i<kk.size();i++){
        for(int j=i+1;j<kk.size();j++){
            ans[color[in]]+=kk[i]*kk[j];
        }
        ans[color[in]]+=kk[i];
    }
}
int main()
{
   
    cin>>n;
    ll c[n+1]={0};
    for(int i=1;i<=n;i++){
        cin>>color[i];
        c[color[i]]++;
    }
    ll u,v;
    for(int i=1;i<n;i++){
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    int vis[n+1]={0};
    dfs(1,vis);
    for(int i=1;i<=n;i++){
        ans[i]-=((c[i]-1)*((c[i]-1)*c[i])/2);
        cout<<ans[i]<<endl;
    }
}

Compiler output:
a.cc: In function 'void dfs(int, int*)':
a.cc:26:10: error: found ':' in nested-name-specifier, expected '::'
   26 |     for(v:adj[in]){
      |          ^
      |          ::
a.cc:26:9: error: 'v' has not been declared
   26 |     for(v:adj[in]){
      |         ^
a.cc:34:5: error: expected primary-expression before 'for'
   34 |     for(int i=0;i<kk.size();i++){
      |     ^~~
a.cc:33:45: error: expected ')' before 'for'
   33 |     ans[color[in]]+=(n-child[in])*child[in];
      |                                             ^
      |                                             )
   34 |     for(int i=0;i<kk.size();i++){
      |     ~~~                                      
a.cc:26:8: note: to match this '('
   26 |     for(v:adj[in]){
      |        ^
Language: C

#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define bit(idx) idx&(-idx)
#define bin(x, a) bitset<a>(x)
#define all(A) A.begin(), A.end()
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;

const int MAXN = 2e5 + 5;

ll n, c[MAXN], A[MAXN], dp[MAXN], answer[MAXN];
vector<int> G[MAXN];

void dfs(int u, int p, int d){
	for(int i = 0; i < G[u].size(); i ++){
		int v = G[u][i];
		if(v != p){
			dfs(v, u, d);
			if(c[u] != d){
				dp[u] += dp[v];
				dp[v] = 0;
			}
		}
	}
	if(c[u] != d)
		++ dp[u];
}

int main(){
	ios_base::sync_with_stdio(NULL); cin.tie(); cout.tie();
	set<int> color;
	cin >> n;
	for(int i = 1; i <= n; i ++){
		cin >> c[i];
		++ A[c[i]];
		color.insert(c[i]);
	}
	for(int i = 0; i < n - 1; i ++){
		int u, v; cin >> u >> v;
		G[u].pb(v);
		G[v].pb(u);
	}
	for(auto i : color){
		memset(dp, 0, (n + 1) * sizeof(ll));
		dfs(1, 1, i);
		vector<ll> blocks;
		ll ans = 0, add = 0;
		ans += A[i] * (A[i] + 1) / 2 + A[i] * (n - A[i]);
		for(int i = 1; i <= n; i ++){
			if(dp[i]){
				add += dp[i] * (n - dp[i] - A[i]);
			}
		}
		ans += add / 2;
		answer[i] = ans;
	}
	for(int i = 1; i <= n; i ++)
		cout << answer[i] << endl;
}
/**

*/

Compiler output:
main.c:1:9: fatal error: bits/stdc++.h: No such file or directory
    1 | #include<bits/stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
#define see(x) cerr<<#x<<"="<<x<<endl;
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll fast(ll x,ll n) {ll ans=1;for(;n;n>>=1,x=x*x%mod) if(n&1) ans=ans*x%mod; return ans;}
const int N=1e6+100;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}
ll c(ll x) {
    return x*(x+1)/2;
}
ll ans[N],siz[N],temp[N],a[N],n;
vector<int>edge[N];

void dfs(int x,int f) {
    ll t=temp[a[x]];
    siz[x]=1;
    for(auto v:edge[x]) if(v!=f) {
        ll pre=temp[a[x]];
        dfs(v,x);siz[x]+=siz[v];
        ans[a[x]]-=c(siz[v]-(temp[a[x]]-pre));
    }
    temp[a[x]]=t+siz[x];
}
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=read();
    for(int i=1;i<n;i++) {
        int u,v;
        u=read();b=read();
        //scanf("%d%d",&u,&v);
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    dfs(1,0);
    for(int i=1;i<=n;i++) {
        ans[i]+=c(n)-c(n-temp[i]);
        printf("%lld\n",ans[i]);
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:30:18: error: 'b' was not declared in this scope
   30 |         u=read();b=read();
      |                  ^
Language: C

#include<bits/stdc++.h>
#define GO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
const int N = 5e5 + 5;
const int M = 1e6 + 5;
const int Mod = 998244353;

ll n, a[N];
vec G[N];
int sz[N];
ll ans[N];
int cnt[N];
bool vis[N];
int big[N];

ll f(ll x)
{
	return x * (x + 1) / 2;
}

void GetSz(int u, int p)
{
	sz[u] = 1;
	big[u] = -1;
	for (auto v : G[u])
		if (v != p)
		{
			GetSz(v, u);
			sz[u] += sz[v];
			if (big[u] == -1 || sz[big[u]] < sz[v])
				big[u] = v;
		}
}

void add(int u, int p, int val)
{
	if (val == 1)
	{
		if (vis[a[u]] == 0)
			cnt[a[u]] += sz[u];
	}
	else
	{
		if (vis[a[u]] == 0)
			cnt[a[u]] -= sz[u];
	}
	vis[a[u]] = true;
	for (auto v : G[u])
		if (v != p)
			add(v, u, val);
	vis[a[u]] = false;
}

void DFS(int u, int p, bool keep)
{
	for (auto v : G[u])
		if (v != p && v != big[u])
			DFS(v, u, 0);
	if (big[u] != -1)
		DFS(big[u], u, 1);
	for (auto v : G[u])
		if (v != p && v != big[u])
			add(v, u, 1);
	int c = a[u];
	ans[c] += f(sz[u] - 1 - cnt[c]);
	if (keep == 0)
	{
		for (auto v : G[u])
			if (v != p)
				add(v, u, -1);
	}
	else cnt[a[u]] = sz[u];
}


int main()
{
	GO;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++)
	{
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	GetSz(1, 1);
	DFS(1, 1, 1);
	for (int i = 1; i <= n; i++)
		if (i != a[1])
			ans[i] += f(sz[1] - cnt[i]);
	for (int i = 1; i <= n; i++)
		cout << n * (n + 1) / 2 - ans[i] << ' ';
	return 0;
}

Compiler output:
main.c:1:9: fatal error: bits/stdc++.h: No such file or directory
    1 | #include<bits/stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void read(int &x){
	read("%d",&x);
}
void write(ll x){
	if (x>9) write(x/10);
	putchar(x%10+'0'); 
}
int n,a[200004],sub[200004];
vector<int>g[200004],v[200004];
ll ans[200004];
int ans1[200004],res[200004];
void dfs(int x,int par){
	sub[x]=1;
	for (int i=0;i<g[x].size();i++)if(g[x][i]!=par)
		dfs(g[x][i],x),sub[x]+=sub[g[x][i]];
}
void dfs1(int x,int par){
	if (v[a[x]].empty()) ans1[a[x]]-=sub[x];
	else res[v[a[x]][v[a[x]].size()-1]]-=sub[x];
	for (int i=0;i<g[x].size();i++) if (g[x][i]!=par){
		v[a[x]].push_back(g[x][i]);
		dfs1(g[x][i],x);
		ans[a[x]]+=1ll*res[g[x][i]]*(res[g[x][i]]+1)/2;
		v[a[x]].pop_back(); 
	}
}
int x,y;
ll A;
int main(){
	read(n),A=1ll*n*(n+1)/2;
	for (int i=1;i<=n;i++) read(a[i]),ans1[i]=n;
	for (int i=1;i<n;i++)read(x),read(y),g[x].push_back(y),g[y].push_back(x); 
	dfs(1,-1);
	for (int i=1;i<=n;i++) res[i]=sub[i];
	dfs1(1,-1);
	for (int i=1;i<=n;i++){
		ll res=A-ans[i]-1ll*ans1[i]*(ans1[i]+1)/2;
		write(res),puts("");
	}
}

Compiler output:
a.cc: In function 'void read(int&)':
a.cc:5:13: error: no matching function for call to 'read(const char [3], int*)'
    5 |         read("%d",&x);
      |         ~~~~^~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/14/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:116,
                 from a.cc:1:
/usr/include/unistd.h:371:16: note: candidate: 'ssize_t read(int, void*, size_t)'
  371 | extern ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur
      |                ^~~~
/usr/include/unistd.h:371:16: note:   candidate expects 3 arguments, 2 provided
a.cc:4:6: note: candidate: 'void read(int&)'
    4 | void read(int &x){
      |      ^~~~
a.cc:4:6: note:   candidate expects 1 argument, 2 provided
Language: C

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

ll n;
vector<int> c;
vector<vector<int>> g;
vector<ll> ans;
vector<ll> siz;

ll sdfs(int pre,int now){
    ll ret=1;
    for(auto to:g[now])if(pre!=to) ret+=sdfs(now,to);
    return siz[now]=ret;
}


map<ll,ll> dfs(int pre,int now){
    vector<map<ll,ll>> v;
    for(auto to:g[now])if(pre!=to){
        auto mp=dfs(now,to);
        ll k=siz[to]-mp[c[now]];
        ans[c[now]]+=k*(k+1)/2;
        v.push_back(mp);
    }
    if(v.empty()){
        map<ll,ll> k;k[c[now]]++;
        return k;
    }
    sort(ALL(v),[](map<ll,ll> a,map<ll,ll> b){return a.size()>b.size();});
    for(int i=1;i<v.size();i++)for(auto &p:v[i]) v[0][p.first]+=p.second;
    v[0][c[now]]=siz[now];
    return v[0];
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    cin>>n;
    c.resize(n);g.resize(n);ans.resize(n,0);siz.resize(n);
    rep(i,n){
        cin>>c[i];c[i]--;
    }
    rep(i,n-1){
        int u,v;cin>>u>>v;u--,v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    sdfs(-1,0);
    auto las=dfs(-1,0);
    for(auto &p:las){
        ll k=n-p.second;
        ans[p.first]+=k*(k+1)/2;
    }
    rep(i,n) cout<<(ans[i]?n*(n+1)/2-ans[i]:0)<<endl;
    return 0;
}


Compiler output:
main.c:1:9: fatal error: bits/stdc++.h: No such file or directory
    1 | #include<bits/stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

//#include<bits\stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define INF 1000000000
#define ldb long double
#define pb push_back
#define get(x) x=read()
#define gt(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define gc(a) scanf("%s",a+1)
#define rep(p,n,i) for(RE int i=p;i<=n;++i)
#define go(x) for(int i=lin[x],tn=ver[i];i;tn=ver[i=nex[i]])
#define fep(n,p,i) for(RE int i=n;i>=p;--i)
#define pii pair<int,int> 
#define mk make_pair
#define RE register
#define P 1000000007
#define S second
#define F first
#define mod 998244353
#define gf(x) scanf("%lf",&x)
#define pf(x) ((x)*(x))
#define ull unsigned long long
#define ui unsigned
using namespace std;
char buf[1<<15],*fs,*ft;
inline char getc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline int read()
{
    register int x=0,f=1;register char ch=getc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
    return x*f;
}
const int MAXN=200010;
int n,len;
ll ans[MAXN];
int a[MAXN],sz[MAXN],s[MAXN];
int lin[MAXN],ver[MAXN<<1],nex[MAXN<<1];
inline void add(int x,int y)
{
	ver[++len]=y;
	nex[len]=lin[x];
	lin[x]=len;
}
inline ll SUM(int x){return (ll)x*(x-1)/2;}
inline void dfs(int x,int father)
{
	sz[x]=1;int ss=s[a[x]],pre=s[a[x]];
	go(x)
	{
		if(tn==father)continue;
		dfs(tn,x);
		sz[x]+=sz[tn];
		ans[a[x]]-=SUM(sz[tn]-(s[a[x]]-pre));
		pre=s[a[x]];
	}
	s[a[x]]=ss+sz[x];
}
int main()
{
	//freopen("1.in","r",stdin);
	get(n);
	rep(1,n,i)get(a[i]),++ans[a[i]],ans[i]+=SUM(n);
	rep(2,n,i)
	{
		int get(x);int get(y);
		add(x,y);add(y,x);
	}
	dfs(1,0);
	rep(1,n,i)ans[i]-=SUM(n-s[i]);
	rep(1,n,i)putl(ans[i]);
	return 0;
}


Compiler output:
main.c:2:9: fatal error: iostream: No such file or directory
    2 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C

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

// 0-indexed
template <class T>
struct BIT {
  int treesize;
  vector<T> lst;
  // constructor
  BIT(int newn = 0) : treesize(newn), lst(newn + 1, 0) {}
  // a_place += num
  void add(int place, T num) {
    ++place;
    while (place <= treesize) {
      lst[place] += num;
      place += place & -place;
    }
  }
  // sum between [0,place)
  T sum(int place) {
    T res = 0;
    while (place > 0) {
      res += lst[place];
      place -= place & -place;
    }
    return res;
  }
  // sum [l,r)
  T sum(int left, int right) { return sum(right) - sum(left); }
};

struct EulerTour {
  int n, root;
  vector<vector<int>> g;
  vector<int> par, dep, in, out, lst;
  EulerTour(int n = 1, int _root = 0)
      : root(_root), g(n), par(n), dep(n), in(n), out(n) {}
  EulerTour(const vector<vector<int>> &_g, const int _root = 0)
      : root(_root),
        g(_g),
        par(_g.size()),
        dep(_g.size()),
        in(_g.size()),
        out(_g.size()) {
    build();
  }
  void add(int a, int b) {
    g[a].push_back(b);
    g[b].push_back(a);
  }
  void build() {
    lst.clear();
    dfs(root, -1, 0);
  }
  void dfs(int now, int bf, int d) {
    dep[now] = d;
    par[now] = bf;
    in[now] = lst.size();
    lst.push_back(now);
    for (auto &to : g[now])
      if (to != bf) {
        dfs(to, now, d + 1);
        lst.push_back(now);
      }
    if (lst.back() != now) lst.push_back(now);
    out[now] = lst.size();
  }
  int chil(int x, int y) { return dep[x] < dep[y] ? y : x; }
};


long long n;
vector<int> c;
vector<vector<int>> edge, col, memo;

void solve();

int main() {
  cin >> n;
  c.resize(n);
  edge.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    --c[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  solve();
  return 0;
}

void solve() {
  EulerTour et(edge);
  BIT<long long> bit(et.lst.size());
  col.resize(n);
  memo.resize(n);
  for (int i = 0; i < n; ++i) bit.add(et.in[i], 1);
  for (int i = 0; i < et.lst.size(); ++i) memo[et.lst[i]].push_back(i);
  for (int i = 0; i < n; ++i) col[c[i]].push_back(i);
  for (int i = 0; i < n; ++i) {
    long long res = n * (n + 1) / 2;
    using P = pair<int, int>;
    vector<P> v;
    map<int, int> mp;
    for (int node : col[i]) {
      bit.add(et.in[node], -1);
      mp[node] = 1;
      for (int id = 0; id < (int)memo[node].size() - 1; ++id)
        v.emplace_back(memo[node][id + 1], node);
    }
    sort(v.begin(), v.end());
    for (P p : v) {
      long long now = bit.sum(et.in[p.second], p.first);
      res -= now * (now + 1) / 2;
      mp[p.second] += now;
      bit.add(et.in[p.second], -now);
    }
    long long last = bit.sum(et.lst.size());
    res -= last * (last + 1) / 2;
    cout << res << endl;
    for (auto p : mp) bit.add(et.in[p.first], p.second);
  }
}


Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll n;
    cin >> n;
    vector<ll> ans(n, n*(n-1)/2);
    vector<int> sub(n, 1), cnt(n);
    vector<int> C(n);
    for (auto &&i : C) scanf("%d", &i), i--, ans[i]++;
    vector<vector<int>> G(n);
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    int up = 0;
    auto dfs = [&](int i, int par, auto &&f) -> void {
        int tmp = cnt[C[i]];
        for (auto &&j : G[i]) {
            if(j == par) continue;
            ll x = -(up-cnt[C[i]]);
            f(j, i, f);
            sub[i] += sub[j];
            x += up-cnt[C[i]];
            ans[C[i]] -= x*(x-1)/2;
        }
        up++;
        cnt[C[i]] = tmp+sub[i];
    };
    dfs(0, -1, dfs);
    cout << cnt[0] << "\n";
    for (int i = 0; i < n; ++i){
        printf("%lld\n", ans[i]-(n-cnt[i])*(n-cnt[i]-1)/2); 
    }
    return 0;
}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;

#define rep(i,m,n) for(int i=m;i<n;i++)




int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    int c[n];
    rep(i,0,n){cin>>c[i];c[i]--;}
    vector<int> v[n];
    rep(i,0,n-1){
        int a,b;cin>>a>>b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ll ans[n];
    fill(ans,ans+n,n*(n+1)/2);
    ll cnt[n];
    fill(cnt,cnt+n,0);
    vector<map<ll,ll>> dp(n);
    auto dfs = [&](auto&& dfs,int i,int p)->void{
        for(int ne:v[i]){
            if(ne!=p){
                dfs(dfs,ne,i);
                cnt[i]+=cnt[ne];
                ll gg=cnt[ne];
                if(dp[ne].count(c[i]))gg-=dp[ne][c[i]];
               // cout<<i<<" "<<g<<endl;
                ans[c[i]]-=gg*(gg+1)/2;
                if(dp[i].size()<dp[ne].size())swap(dp[i],dp[ne]);
                for(auto& p:dp[ne])dp[i][p.first]+=p.second;
            }
        }
        cnt[i]++;
        dp[i][c[i]]=cnt[i];
    };
    dfs(dfs,0,-1);
    
    rep(i,0,n){
        ll sa=n-dp[0][i];
        ans[i]-=sa*(sa+1)/2;
        cout<<ans[i]<<endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:30:16: error: use of deleted function 'main()::<lambda(auto:28&&, int, int)>::~<lambda>()'
   30 |     auto dfs = [&](auto&& dfs,int i,int p)->void{
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |         for(int ne:v[i]){
      |         ~~~~~~~~~~~~~~~~~
   32 |             if(ne!=p){
      |             ~~~~~~~~~~
   33 |                 dfs(dfs,ne,i);
      |                 ~~~~~~~~~~~~~~
   34 |                 cnt[i]+=cnt[ne];
      |                 ~~~~~~~~~~~~~~~~
   35 |                 ll gg=cnt[ne];
      |                 ~~~~~~~~~~~~~~
   36 |                 if(dp[ne].count(c[i]))gg-=dp[ne][c[i]];
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |                // cout<<i<<" "<<g<<endl;
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~
   38 |                 ans[c[i]]-=gg*(gg+1)/2;
      |                 ~~~~~~~~~~~~~~~~~~~~~~~
   39 |                 if(dp[i].size()<dp[ne].size())swap(dp[i],dp[ne]);
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   40 |                 for(auto& p:dp[ne])dp[i][p.first]+=p.second;
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   41 |             }
      |             ~   
   42 |         }
      |         ~       
   43 |         cnt[i]++;
      |         ~~~~~~~~~
   44 |         dp[i][c[i]]=cnt[i];
      |         ~~~~~~~~~~~~~~~~~~~
   45 |     };
      |     ~           
a.cc:30:18: note: 'main()::<lambda(auto:28&&, int, int)>::~<lambda>()' is implicitly deleted because the default definition would be ill-formed:
   30 |     auto dfs = [&](auto&& dfs,int i,int p)->void{
      |                  ^
Language: C++

#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;

#define rep(i,m,n) for(ll i=m;i<n;i++)




int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n;cin>>n;
    int c[n];
    rep(i,0,n){cin>>c[i];c[i]--;}
    vector<int> v[n];
    rep(i,0,n-1){
        int a,b;cin>>a>>b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ll ans[n];
    fill(ans,ans+n,n*(n+1)/2);
    ll cnt[n];
    fill(cnt,cnt+n,0);
    vector<map<ll,ll>> dp(n);
    auto dfs = [&](auto&& dfs,int i,int p)->void{
        for(int ne:v[i]){
            if(ne!=p){
                dfs(dfs,ne,i);
                cnt[i]+=cnt[ne];
                ll gg=cnt[ne];
                if(dp[ne].count(c[i]))gg-=dp[ne][c[i]];
               // cout<<i<<" "<<g<<endl;
                ans[c[i]]-=gg*(gg+1)/2;
                if(dp[i].size()<dp[ne].size())swap(dp[i],dp[ne]);
                for(auto& p:dp[ne])dp[i][p.first]+=p.second;
            }
        }
        cnt[i]++;
        dp[i][c[i]]=cnt[i];
    };
    dfs(dfs,0,-1);
    //rep(i,0,n)cout<<dp[0][i]<<" ";
    //cout<<endl;
    rep(i,0,n){
        ll sa=n-dp[0][i];
        ans[i]-=sa*(sa+1)/2;
        cout<<ans[i]<<endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:30:16: error: use of deleted function 'main()::<lambda(auto:28&&, int, int)>::~<lambda>()'
   30 |     auto dfs = [&](auto&& dfs,int i,int p)->void{
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |         for(int ne:v[i]){
      |         ~~~~~~~~~~~~~~~~~
   32 |             if(ne!=p){
      |             ~~~~~~~~~~
   33 |                 dfs(dfs,ne,i);
      |                 ~~~~~~~~~~~~~~
   34 |                 cnt[i]+=cnt[ne];
      |                 ~~~~~~~~~~~~~~~~
   35 |                 ll gg=cnt[ne];
      |                 ~~~~~~~~~~~~~~
   36 |                 if(dp[ne].count(c[i]))gg-=dp[ne][c[i]];
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |                // cout<<i<<" "<<g<<endl;
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~
   38 |                 ans[c[i]]-=gg*(gg+1)/2;
      |                 ~~~~~~~~~~~~~~~~~~~~~~~
   39 |                 if(dp[i].size()<dp[ne].size())swap(dp[i],dp[ne]);
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   40 |                 for(auto& p:dp[ne])dp[i][p.first]+=p.second;
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   41 |             }
      |             ~   
   42 |         }
      |         ~       
   43 |         cnt[i]++;
      |         ~~~~~~~~~
   44 |         dp[i][c[i]]=cnt[i];
      |         ~~~~~~~~~~~~~~~~~~~
   45 |     };
      |     ~           
a.cc:30:18: note: 'main()::<lambda(auto:28&&, int, int)>::~<lambda>()' is implicitly deleted because the default definition would be ill-formed:
   30 |     auto dfs = [&](auto&& dfs,int i,int p)->void{
      |                  ^
Language: C

#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename F>
struct FixPoint : F{
    FixPoint(F&& f):F(forward<F>(f)){}
    template<typename... Args>
    decltype(auto) operator()(Args&&... args) const{
        return F::operator()(*this,forward<Args>(args)...);
    }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
    return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n;
    cin>>n;
    vector<int> cs(n);
    for(int i=0;i<n;i++) cin>>cs[i],cs[i]--;

    vector<vector<int>> G(n);
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    using ll = long long;
    ll all=0;
    vector<ll> cnt(n,0),sub(n,0);

    vector<ll> ans(n,(ll)n*(n-1)/2);
    MFP([&](auto dfs,int v,int p)->int{
        sub[v]=1;//nodes
        ll bfr=cnt[cs[v]];
        int soncnt = 0;
        for(int u:G[v]){
            if(u==p) continue;
            soncnt++;
            ll precv = cnt[cs[v]];
            //if (1==soncnt && pre)
            sub[v]+=dfs(u,v);
            ll nxt=sub[u]-(cnt[cs[v]]-precv);
            ans[cs[v]]-=(nxt-pre)*(nxt-pre-1)/2;//subtree of u which not go throw color cs[v]
        }
        cnt[cs[v]]=bfr+sub[v];
        all++;
        return sub[v];
    })(0,-1);

    for(int c=0;c<n;c++){
        ll pre=0,nxt=n-cnt[c];
        ans[c]-=(nxt-pre)*(nxt-pre-1)/2;
    }
    for(int c:cs) ans[c]++;

    for(ll a:ans) cout<<a<<newl;
    return 0;
}


Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#pragma warning(disable:4996)

using namespace std;

vector<long long> c, parent, d, ct, ans;
vector<bool> used;
vector<vector<int>> adj, plist;

void dfs(int id) {
	ct[id] = 1;
	long long x, s, ss = 0, v;
	for (auto p : adj[id]) {
		if (parent[p] == -1) {
			parent[p] = id;

			x = plist[c[id]].size();
			s = 0;
			dfs(p);
			while (plist[c[id]].size() > x) {
				s += plist[c[id]].back();
				plist[c[id]].pop_back();
			}

			ct[id] += ct[p];

			v = ct[p] - s;
			ans[c[id]] += v * (v - 1) / 2 + v;
			ss += s;
		}
	}

	plist[c[id]].push_back(ct[id]);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	long long n, i, j, k, a, b, level, x, total;
	cin >> n;
	c.resize(n + 1);
	used.assign(n + 1, false);
	for (i = 1; i <= n; i++) {
		cin >> c[i];
		used[c[i]] = true;
	}
	adj.resize(n + 1);
	for (i = 0; i < n - 1; i++) {
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	parent.assign(n + 1, -1);
	parent[1] = 0;
	ct.resize(n + 1);
	plist.resize(n + 1);

	ans.assign(n + 1, 0);
	dfs(1);

	for (i = 1; i <= n; i++) {
		if (used[i]) {
			ans[i] += (n - plist[i][0]) * (n - plist[i][0] - 1) / 2 + (n - plist[i][0]);
			ans[i] = n * (n - 1) / 2 + n - ans[i];
		}
		cout << ans[i] << "\n";
	}

	return 0;
}


Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200005
#define int long long
#define il inline
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define  pi  acos(-1)
#define ld  double
#define mod 1000000007
#pragma GCC optimize(2)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int c[N];
vector<ll> g[N],ans;
int sz[N],cnt[N];
void dfs1(int x,int fa){
    sz[x]=1;
    for(auto i:g[x]){
        if(i!=fa){
            dfs1(i,x);
            sz[x]+=sz[i];
        }
    }
}
void dfs2(int x,int fa){
    int tmp=cnt[c[x]];
    for(auto i:g[x]){
        if(i==fa)continue;
        int now=cnt[c[x]];
        dfs2(i,x);
        int dif=cnt[c[x]]-now;
        int d=sz[i]-dif;
        ans[c[x]]-=(d-1)*d/2;
    }
    cnt[c[x]]=tmp+sz[x];
}
int main() {
   // IOS
    int n;
    cin>>n;
    memset(cnt,0, sizeof(cnt));
    ans.assign(n+10,n*(n-1)/2);
    for(int i=1;i<=n;i++){cin>>c[i];ans[c[i]]++;}
    for (int j = 0; j <n-1 ; ++j) {
        int u,v;
        cin>>u>>v;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    dfs1(1,0);
    dfs2(1,0);
    for (int i = 1; i <=n ; ++i) {
        ans[i]-=(n-cnt[i])*(n-cnt[i]-1)/2;
    }
    for (int i = 1; i <=n ; ++i) {
        cout<<ans[i]<<endl;
    }
    return 0;
}

Compiler output:
cc1plus: error: '::main' must return 'int'