Hello everybody and welcome to the first summer round - Codeforces Beta Round #73.

Today we are the authors of round: kuniavski (Pavel Kunyavskiy) and Zlobober (Max Akhmedov). Competition will take place in both divisions. Totally there will be 7 different problems with variations in divisions, 5 in each division. We hope everybody shows their best and solve as many problem as they can.

Thanks to RAD (Artem Rakhov) for the help and advices in preparing of the round, Delinur (Maria Belova) for the problem translation and MikeMirzayanov (Michael Mirzayanov) for such a great site.

GL & HF!

Congratulations to the winners

Div1 - ilyakor

Div2 - peter50216

Some statistics. First sucsessful submits and hacks:

Div1-A Dmitry_Egorov 4:09

Div1-B ilyakor 13:05

Div1-C A_A_Lunyov 8:05

Div1-D hos.lyric 30:57

Div1-E rng_58 75:20

hack VArtem 26:15

Div2-A epizend 5:27

Div2-B random.johnnyh 19:15:29

Div2-C RomaFurko 11:31

Div2-D peter50216 41:18

Div2-E peter50216 54:00

hack diogen 55:33

bothdivisions.Each division has, as usual, 5 problems.

It means that 3 problems will be common for each division.

I think, it was at bit disbalanced: first two problems was simple, C was classical, D and E required a lots of code.

Fill the grundy table g[0...N] and each g[X] means you have a game of X piles. Try all possible moves, i.e., all possible K such that X = a * K + (K*(K-1))/2 , which results in subgames {a,a+1,a+2,....,a+K-1}. The grundy of the collection of these subgames is ( g[a] ^ g[a+1] ^ ... ^ g[a+K-1] ). Some coders just iterated and found this value, but you can simply maintain a prefix xor on g[ ] , say pg[ ] and get it using pg[a+K-1] ^ pg[a-1] in O(1). g[X] = the mex among all grundy values reachable from X. Complexity is O( n . sqrt(n) )

This round may be easier than past round (Div2). Normally, I solve only one problem during contest, but today i solve 3 problems

Main idea is that we sort edges and add by groups in the graph, counting for each new edge all the paths that include it using DSU.

disjoint-set data structure. Try to guess how an abbreviationDSUis formed :)b=999999

gcd(a,b)=1;

a*gcd(a,b)=1000000;

a*b>2^31-1

An attempt to use the data type that hasn't been defined before that will also lead to the errtype."By the way, the link to the tutorials is wrong.

greetings

When I used scanf("%lld%lld",&a,&b); --- it gave me wrong answer.

But when I used cin>>a>>b; --- the solution was accepted!!

What was the problem? Anyone please reply.

That wasted my 25 minutes :sob:

Concerning problem D,

I wonder if if final tests contained this type of a test:

We have a large tree with this structure -

4

1 2 1

2 3 2

3 4 3

It is a straight line tree with the largest weight edge at the bottom.

I m guessing final tests, skipped such a case. I could notice solutions without the use of DSU pass the system tests but fail this one.

Appreciate a reply.