Language: C++

#include<bits/stdc++.h>
#define U [100005]={}
typedef long long L;using namespace std;map<L,L> path U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;D(L a){Z[a]=1;for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){L d=I->first;if(d-P[a]){P[d]=a;E[d]=E[a]+1;C[d]=I->second;D(d);Z[a]+=Z[d];!H[a]|Z[H[a]]<Z[d]?H[a]=d:0;}}}L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}L M(L i){for(r=0;i;r+=B[i],i-=i&-i);return r;}L S(L i,L x){for(x=G(x)-M(i+1)+M(i++);i<100005;B[i]+=x,i+=i&-i);}main(){for(cin>>n>>k;p<n-1;p++)cin>>a>>b>>c,path[a][b]=path[b][a]=c;D(0);for(c=p=0;p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;a=H[a])O[a]=c++,X[a]=p,S(O[a],H[a]);for(cin>>a;cin>>s>>a>>b;)if(*s&2){for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}else A[a]+=b,S(O[a],H[a]),a?S(O[a]-1,a):0;}

Compiler output:
a.cc:3:118: error: ISO C++ forbids declaration of 'D' with no type [-fpermissive]
    3 | typedef long long L;using namespace std;map<L,L> path U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;D(L a){Z[a]=1;for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){L d=I->first;if(d-P[a]){P[d]=a;E[d]=E[a]+1;C[d]=I->second;D(d);Z[a]+=Z[d];!H[a]|Z[H[a]]<Z[d]?H[a]=d:0;}}}L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}L M(L i){for(r=0;i;r+=B[i],i-=i&-i);return r;}L S(L i,L x){for(x=G(x)-M(i+1)+M(i++);i<100005;B[i]+=x,i+=i&-i);}main(){for(cin>>n>>k;p<n-1;p++)cin>>a>>b>>c,path[a][b]=path[b][a]=c;D(0);for(c=p=0;p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;a=H[a])O[a]=c++,X[a]=p,S(O[a],H[a]);for(cin>>a;cin>>s>>a>>b;)if(*s&2){for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}else A[a]+=b,S(O[a],H[a]),a?S(O[a]-1,a):0;}
      |                                                                                                                      ^
a.cc: In function 'int D(L)':
a.cc:3:299: warning: no return statement in function returning non-void [-Wreturn-type]
    3 | typedef long long L;using namespace std;map<L,L> path U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;D(L a){Z[a]=1;for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){L d=I->first;if(d-P[a]){P[d]=a;E[d]=E[a]+1;C[d]=I->second;D(d);Z[a]+=Z[d];!H[a]|Z[H[a]]<Z[d]?H[a]=d:0;}}}L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}L M(L i){for(r=0;i;r+=B[i],i-=i&-i);return r;}L S(L i,L x){for(x=G(x)-M(i+1)+M(i++);i<100005;B[i]+=x,i+=i&-i);}main(){for(cin>>n>>k;p<n-1;p++)cin>>a>>b>>c,path[a][b]=path[b][a]=c;D(0);for(c=p=0;p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;a=H[a])O[a]=c++,X[a]=p,S(O[a],H[a]);for(cin>>a;cin>>s>>a>>b;)if(*s&2){for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}else A[a]+=b,S(O[a],H[a]),a?S(O[a]-1,a):0;}
      |                                                                                                                                                                                                                                                                                                           ^
a.cc: In function 'L S(L, L)':
a.cc:3:455: warning: no return statement in function returning non-void [-Wreturn-type]
    3 | typedef long long L;using namespace std;map<L,L> path U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;D(L a){Z[a]=1;for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){L d=I->first;if(d-P[a]){P[d]=a;E[d]=E[a]+1;C[d]=I->second;D(d);Z[a]+=Z[d];!H[a]|Z[H[a]]<Z[d]?H[a]=d:0;}}}L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}L M(L i){for(r=0;i;r+=B[i],i-=i&-i);return r;}L S(L i,L x){for(x=G(x)-M(i+1)+M(i++);i<100005;B[i]+=x,i+=i&-i);}main(){for(cin>>n>>k;p<n-1;p++)cin>>a>>b>>c,path[a][b]=path[b][a]=c;D(0);for(c=p=0;p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;a=H[a])O[a]=c++,X[a]=p,S(O[a],H[a]);for(cin>>a;cin>>s>>a>>b;)if(*s&2){for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}else A[a]+=b,S(O[a],H[a]),a?S(O[a]-1,a):0;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ^
a.cc: At global scope:
a.cc:3:456: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    3 | typedef long long L;using namespace std;map<L,L> path U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;D(L a){Z[a]=1;for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){L d=I->first;if(d-P[a]){P[d]=a;E[d]=E[a]+1;C[d]=I->second;D(d);Z[a]+=Z[d];!H[a]|Z[H[a]]<Z[d]?H[a]=d:0;}}}L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}L M(L i){for(r=0;i;r+=B[i],i-=i&-i);return r;}L S(L i,L x){for(x=G(x)-M(i+1)+M(i++);i<100005;B[i]+=x,i+=i&-i);}main(){for(cin>>n>>k;p<n-1;p++)cin>>a>>b>>c,path[a][b]=path[b][a]=c;D(0);for(c=p=0;p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;a=H[a])O[a]=c++,X[a]=p,S(O[a],H[a]);for(cin>>a;cin>>s>>a>>b;)if(*s&2){for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}else A[a]+=b,S(O[a],H[a]),a?S(O[a]-1,a):0;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ^~~~