Language: C++

#include<bits/stdc++.h>
#define U [7<<15]={}
#define G )+((c=A[a]+A[P[a]]+C[a])%k?c:0)-M(
typedef long long L;using namespace std;map<L,L>T 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;char s U;L M(L f){return f?B[f]+M(f^f&-f):0;}L S(L f,L i){for(f=M(i++G i);i<2e5;i+=i&-i)B[i]+=f;}L D(L f){L d;Z[f]=1;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,!Z[d]?P[d]=f,E[d]=E[f]+1,C[d]=I->second,D(d),Z[f]+=Z[d],!H[f]|Z[H[f]]<Z[d]?H[f]=d:0:0;}aL K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}amain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)for(;!b|a;S(a=H[a],O[a]=++b))X[a]=n;for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}

Compiler output:
a.cc: In function 'L S(L, L)':
a.cc:4:197: warning: no return statement in function returning non-void [-Wreturn-type]
    4 | typedef long long L;using namespace std;map<L,L>T 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;char s U;L M(L f){return f?B[f]+M(f^f&-f):0;}L S(L f,L i){for(f=M(i++G i);i<2e5;i+=i&-i)B[i]+=f;}L D(L f){L d;Z[f]=1;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,!Z[d]?P[d]=f,E[d]=E[f]+1,C[d]=I->second,D(d),Z[f]+=Z[d],!H[f]|Z[H[f]]<Z[d]?H[f]=d:0:0;}aL K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}amain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)for(;!b|a;S(a=H[a],O[a]=++b))X[a]=n;for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}
      |                                                                                                                                                                                                     ^
a.cc: In function 'L D(L)':
a.cc:4:371: warning: no return statement in function returning non-void [-Wreturn-type]
    4 | typedef long long L;using namespace std;map<L,L>T 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;char s U;L M(L f){return f?B[f]+M(f^f&-f):0;}L S(L f,L i){for(f=M(i++G i);i<2e5;i+=i&-i)B[i]+=f;}L D(L f){L d;Z[f]=1;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,!Z[d]?P[d]=f,E[d]=E[f]+1,C[d]=I->second,D(d),Z[f]+=Z[d],!H[f]|Z[H[f]]<Z[d]?H[f]=d:0:0;}aL K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}amain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)for(;!b|a;S(a=H[a],O[a]=++b))X[a]=n;for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}
      |                                                                                                                                                                                                                                                                                                                                                                                   ^
a.cc: At global scope:
a.cc:4:372: error: 'aL' does not name a type; did you mean 'L'?
    4 | typedef long long L;using namespace std;map<L,L>T 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;char s U;L M(L f){return f?B[f]+M(f^f&-f):0;}L S(L f,L i){for(f=M(i++G i);i<2e5;i+=i&-i)B[i]+=f;}L D(L f){L d;Z[f]=1;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,!Z[d]?P[d]=f,E[d]=E[f]+1,C[d]=I->second,D(d),Z[f]+=Z[d],!H[f]|Z[H[f]]<Z[d]?H[f]=d:0:0;}aL K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}amain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)for(;!b|a;S(a=H[a],O[a]=++b))X[a]=n;for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}
      |                                                                                                                                                                                                                                                                                                                                                                                    ^~
      |                                                                                                                                                                                                                                                                                                                                                                                    L
a.cc:4:475: error: ISO C++ forbids declaration of 'amain' with no type [-fpermissive]
    4 | typedef long long L;using namespace std;map<L,L>T 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;char s U;L M(L f){return f?B[f]+M(f^f&-f):0;}L S(L f,L i){for(f=M(i++G i);i<2e5;i+=i&-i)B[i]+=f;}L D(L f){L d;Z[f]=1;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,!Z[d]?P[d]=f,E[d]=E[f]+1,C[d]=I->second,D(d),Z[f]+=Z[d],!H[f]|Z[H[f]]<Z[d]?H[f]=d:0:0;}aL K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}amain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)for(;!b|a;S(a=H[a],O[a]=++b))X[a]=n;for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ^~~~~
a.cc: In function 'int amain()':
a.cc:4:664: error: 'K' was not declared in this scope
    4 | typedef long long L;using namespace std;map<L,L>T 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;char s U;L M(L f){return f?B[f]+M(f^f&-f):0;}L S(L f,L i){for(f=M(i++G i);i<2e5;i+=i&-i)B[i]+=f;}L D(L f){L d;Z[f]=1;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,!Z[d]?P[d]=f,E[d]=E[f]+1,C[d]=I->second,D(d),Z[f]+=Z[d],!H[f]|Z[H[f]]<Z[d]?H[f]=d:0:0;}aL K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}amain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)for(;!b|a;S(a=H[a],O[a]=++b))X[a]=n;for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ^
a.cc:4:685: warning: no return statement in function returning non-void [-Wreturn-type]
    4 | typedef long long L;using namespace std;map<L,L>T 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;char s U;L M(L f){return f?B[f]+M(f^f&-f):0;}L S(L f,L i){for(f=M(i++G i);i<2e5;i+=i&-i)B[i]+=f;}L D(L f){L d;Z[f]=1;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,!Z[d]?P[d]=f,E[d]=E[f]+1,C[d]=I->second,D(d),Z[f]+=Z[d],!H[f]|Z[H[f]]<Z[d]?H[f]=d:0:0;}aL K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}amain(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)for(;!b|a;S(a=H[a],O[a]=++b))X[a]=n;for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ^