XMORE's blog

By XMORE, history, 3 months ago, In English,

Hi guys could know russian lang translate to me problem C to english, by the way google translation is very poor http://codeforces.com/gym/100091/attachments

 
 
 
 
  • Vote: I like it  
  • -3
  • Vote: I do not like it  

»
3 months ago, # |
  Vote: I like it +3 Vote: I do not like it

You are given a tree that consists of N verticles. Root is verticle number 0. You need to answer M queries about LCA of two verticles.

INPUT FORMAT

First string contains N,M

Second string contains N-1 number, i-th number is parent of verticle number i.

Third string contains numbers A0 and A1

4th string contains numbers X,Y,Z

THIS PROBLEM GIVES QUERIES IN AN UGLY WAY

FIRST, NUMBERS A2,A3,...A(2*M-1),A(2*M) ARE GENERATED LIKE THIS:

A(I)=(X*A(I-1)+Y*A(I-2)+Z)%N

1ST QUERY IS [A0, A1]

IF ANSWER FOR (I-1)-TH QUERY IS V, THEN I-TH QUERY IS [(A(2*I-1)+V)%N,A(2*I)]

OUTPUT FORMAT

One number — sum of all answers