Language: C

#define _[2<<17]
n,i;A _,B _,T _,F _;long M,D _,P _,R _;
s(u,i,p,I){R[i]=i?s(u,T[i],p),(I=B[i])-p?s(I,F[I],u),D[u]=D[u]*-~D[I]%M:D[u]:(++D[u],D[u]!=1&&exit(-1),1);}
S(u,x,p,i,I){for(i=F[u];I=B[i];I-p?S(I,R[i]*x%M+1,u),x=x*-~D[I]%M:0)i=T[i];P[u]=x%M;}main(u,v){for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);for(;--i;F[A[i]]=i)T[i]=F[A[i]];s(*R=1,F[1]);for(S(1,1);i++<n;)printf("%d ",P[i]);}

Compiler output:
main.c:1:9: warning: ISO C99 requires whitespace after the macro name
    1 | #define _[2<<17]
      |         ^
main.c:2:1: warning: data definition has no type or storage class
    2 | n,i;A _,B _,T _,F _;long M,D _,P _,R _;
      | ^
main.c:2:1: error: type defaults to 'int' in declaration of 'n' [-Wimplicit-int]
main.c:2:3: error: type defaults to 'int' in declaration of 'i' [-Wimplicit-int]
    2 | n,i;A _,B _,T _,F _;long M,D _,P _,R _;
      |   ^
main.c:2:5: warning: data definition has no type or storage class
    2 | n,i;A _,B _,T _,F _;long M,D _,P _,R _;
      |     ^
main.c:2:5: error: type defaults to 'int' in declaration of 'A' [-Wimplicit-int]
main.c:2:9: error: type defaults to 'int' in declaration of 'B' [-Wimplicit-int]
    2 | n,i;A _,B _,T _,F _;long M,D _,P _,R _;
      |         ^
main.c:2:13: error: type defaults to 'int' in declaration of 'T' [-Wimplicit-int]
    2 | n,i;A _,B _,T _,F _;long M,D _,P _,R _;
      |             ^
main.c:2:17: error: type defaults to 'int' in declaration of 'F' [-Wimplicit-int]
    2 | n,i;A _,B _,T _,F _;long M,D _,P _,R _;
      |                 ^
main.c:3:1: error: return type defaults to 'int' [-Wimplicit-int]
    3 | s(u,i,p,I){R[i]=i?s(u,T[i],p),(I=B[i])-p?s(I,F[I],u),D[u]=D[u]*-~D[I]%M:D[u]:(++D[u],D[u]!=1&&exit(-1),1);}
      | ^
main.c: In function 's':
main.c:3:1: error: type of 'u' defaults to 'int' [-Wimplicit-int]
main.c:3:1: error: type of 'i' defaults to 'int' [-Wimplicit-int]
main.c:3:1: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:3:1: error: type of 'I' defaults to 'int' [-Wimplicit-int]
main.c:3:95: error: implicit declaration of function 'exit' [-Wimplicit-function-declaration]
    3 | s(u,i,p,I){R[i]=i?s(u,T[i],p),(I=B[i])-p?s(I,F[I],u),D[u]=D[u]*-~D[I]%M:D[u]:(++D[u],D[u]!=1&&exit(-1),1);}
      |                                                                                               ^~~~
main.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'exit'
  +++ |+#include <stdlib.h>
    1 | #define _[2<<17]
main.c:3:95: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
    3 | s(u,i,p,I){R[i]=i?s(u,T[i],p),(I=B[i])-p?s(I,F[I],u),D[u]=D[u]*-~D[I]%M:D[u]:(++D[u],D[u]!=1&&exit(-1),1);}
      |                                                                                               ^~~~
main.c:3:95: note: include '<stdlib.h>' or provide a declaration of 'exit'
main.c:3:95: error: void value not ignored as it ought to be
    3 | s(u,i,p,I){R[i]=i?s(u,T[i],p),(I=B[i])-p?s(I,F[I],u),D[u]=D[u]*-~D[I]%M:D[u]:(++D[u],D[u]!=1&&exit(-1),1);}
      |                                                                                               ^~~~~~~~
main.c: At top level:
main.c:4:1: error: return type defaults to 'int' [-Wimplicit-int]
    4 | S(u,x,p,i,I){for(i=F[u];I=B[i];I-p?S(I,R[i]*x%M+1,u),x=x*-~D[I]%M:0)i=T[i];P[u]=x%M;}main(u,v){for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);for(;--i;F[A[i]]=i)T[i]=F[A[i]];s(*R=1,F[1]);for(S(1,1);i++<n;)printf("%d ",P[i]);}
      | ^
main.c: In function 'S':
main.c:4:1: error: type of 'u' defaults to 'int' [-Wimplicit-int]
main.c:4:1: error: type of 'x' defaults to 'int' [-Wimplicit-int]
main.c:4:1: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:4:1: error: type of 'i' defaults to 'int' [-Wimplicit-int]
main.c:4:1: error: type of 'I' defaults to 'int' [-Wimplicit-int]
main.c: At top level:
main.c:4:86: error: return type defaults to 'int' [-Wimplicit-int]
    4 | S(u,x,p,i,I){for(i=F[u];I=B[i];I-p?S(I,R[i]*x%M+1,u),x=x*-~D[I]%M:0)i=T[i];P[u]=x%M;}main(u,v){for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);for(;--i;F[A[i]]=i)T[i]=F[A[i]];s(*R=1,F[1]);for(S(1,1);i++<n;)printf("%d ",P[i]);}
      |                                                                                      ^~~~
main.c: In function 'main':
main.c:4:86: error: type of 'u' defaults to 'int' [-Wimplicit-int]
main.c:4:86: error: type of 'v' defaults to 'int' [-Wimplicit-int]
main.c:4:102: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
    4 | S(u,x,p,i,I){for(i=F[u];I=B[i];I-p?S(I,R[i]*x%M+1,u),x=x*-~D[I]%M:0)i=T[i];P[u]=x%M;}main(u,v){for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);for(;--i;F[A[i]]=i)T[i]=F[A[i]];s(*R=1,F[1]);for(S(1,1);i++<n;)printf("%d ",P[i]);}
      |                                                                                                      ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | #define _[2<<17]
main.c:4:102: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
    4 | S(u,x,p,i,I){for(i=F[u];I=B[i];I-p?S(I,R[i]*x%M+1,u),x=x*-~D[I]%M:0)i=T[i];P[u]=x%M;}main(u,v){for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);for(;--i;F[A[i]]=i)T[i]=F[A[i]];s(*R=1,F[1]);for(S(1,1);i++<n;)printf("%d ",P[i]);}
      |                                                                                                      ^~~~~
main.c:4:102: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:4:230: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
    4 | S(u,x,p,i,I){for(i=F[u];I=B[i];I-p?S(I,R[i]*x%M+1,u),x=x*-~D[I]%M:0)i=T[i];P[u]=x%M;}main(u,v){for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);for(;--i;F[A[i]]=i)T[i]=F[A[i]];s(*R=1,F[1]);for(S(1,1);i++<n;)printf("%d ",P[i]);}
      |                                                                                                                                                                                                                                      ^~~~~~
main.c:4:230: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:4:230: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:4:230: note: include '<stdio.h>' or provide a declaration of 'printf'