Language: C

n,i;A[2<<17],B[2<<17],T[2<<17],F[1<<17];
long M,D[1<<17],P[1<<17],R[2<<17];
s(u,p,i,I){
	D[u]=1;
	for(i=F[u];I=B[i];i=T[i])I-p?s(I,u),D[u]=D[u]*-~D[I]%M:0;
}
S(u,p,x,i,I){
	for(M(i=F[u],p);I=B[i];I-p?S(I,u,R[i]*x%M+1,0,0),x=x*-~D[I]%M:0)i=T[i];
	P[u]=x%M;
}
M(i,p){
	i?M(T[i],p),R[i]=R[T[i]]*(B[i]-p?-~D[B[i]]:1)%M:0;
}
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,0);
	S(1,0,1);
	for(;i++<n;)printf("%d\n",P[i]);
}

Compiler output:
main.c:1:1: warning: data definition has no type or storage class
    1 | n,i;A[2<<17],B[2<<17],T[2<<17],F[1<<17];
      | ^
main.c:1:1: error: type defaults to 'int' in declaration of 'n' [-Wimplicit-int]
main.c:1:3: error: type defaults to 'int' in declaration of 'i' [-Wimplicit-int]
    1 | n,i;A[2<<17],B[2<<17],T[2<<17],F[1<<17];
      |   ^
main.c:1:5: warning: data definition has no type or storage class
    1 | n,i;A[2<<17],B[2<<17],T[2<<17],F[1<<17];
      |     ^
main.c:1:5: error: type defaults to 'int' in declaration of 'A' [-Wimplicit-int]
main.c:1:14: error: type defaults to 'int' in declaration of 'B' [-Wimplicit-int]
    1 | n,i;A[2<<17],B[2<<17],T[2<<17],F[1<<17];
      |              ^
main.c:1:23: error: type defaults to 'int' in declaration of 'T' [-Wimplicit-int]
    1 | n,i;A[2<<17],B[2<<17],T[2<<17],F[1<<17];
      |                       ^
main.c:1:32: error: type defaults to 'int' in declaration of 'F' [-Wimplicit-int]
    1 | n,i;A[2<<17],B[2<<17],T[2<<17],F[1<<17];
      |                                ^
main.c:3:1: error: return type defaults to 'int' [-Wimplicit-int]
    3 | s(u,p,i,I){
      | ^
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 'p' 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 'I' defaults to 'int' [-Wimplicit-int]
main.c: At top level:
main.c:7:1: error: return type defaults to 'int' [-Wimplicit-int]
    7 | S(u,p,x,i,I){
      | ^
main.c: In function 'S':
main.c:7:1: error: type of 'u' defaults to 'int' [-Wimplicit-int]
main.c:7:1: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:7:1: error: type of 'x' defaults to 'int' [-Wimplicit-int]
main.c:7:1: error: type of 'i' defaults to 'int' [-Wimplicit-int]
main.c:7:1: error: type of 'I' defaults to 'int' [-Wimplicit-int]
main.c:8:13: error: called object 'M' is not a function or function pointer
    8 |         for(M(i=F[u],p);I=B[i];I-p?S(I,u,R[i]*x%M+1,0,0),x=x*-~D[I]%M:0)i=T[i];
      |             ^
main.c:2:6: note: declared here
    2 | long M,D[1<<17],P[1<<17],R[2<<17];
      |      ^
main.c: At top level:
main.c:11:1: error: return type defaults to 'int' [-Wimplicit-int]
   11 | M(i,p){
      | ^
main.c:11:1: error: 'M' redeclared as different kind of symbol
main.c:2:6: note: previous declaration of 'M' with type 'long int'
    2 | long M,D[1<<17],P[1<<17],R[2<<17];
      |      ^
main.c: In function 'M':
main.c:11:1: error: type of 'i' defaults to 'int' [-Wimplicit-int]
   11 | M(i,p){
      | ^
main.c:11:1: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:12:54: error: invalid operands to binary % (have 'long int' and 'int (*)()')
   12 |         i?M(T[i],p),R[i]=R[T[i]]*(B[i]-p?-~D[B[i]]:1)%M:0;
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
      |                                 |                    |
      |                                 long int             int (*)()
main.c: At top level:
main.c:14:1: error: return type defaults to 'int' [-Wimplicit-int]
   14 | main(u,v){
      | ^~~~
main.c: In function 'main':
main.c:14:1: error: type of 'u' defaults to 'int' [-Wimplicit-int]
main.c:14:1: error: type of 'v' defaults to 'int' [-Wimplicit-int]
main.c:15:15: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   15 |         for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);
      |               ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | n,i;A[2<<17],B[2<<17],T[2<<17],F[1<<17];
main.c:15:15: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   15 |         for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);
      |               ^~~~~
main.c:15:15: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:15:76: error: lvalue required as left operand of assignment
   15 |         for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);
      |                                                                            ^
main.c:19:21: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   19 |         for(;i++<n;)printf("%d\n",P[i]);
      |                     ^~~~~~
main.c:19:21: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:19:21: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:19:21: note: include '<stdio.h>' or provide a declaration of 'printf'