Comments

Forms connected subgraph in original tree. So all vertices with same type are connected by tree edges. For example 1 to 1,2 to 2 is ok, but 1 to 2 to 1,2 not okay (as 1 and 1,2 should be connected by edge to form connected subtree). It wasn't clear for me too.

Ok, thanks, now I understand that each type of ice cream must form connected subgraph in a tree.

I understand why it's wrong. But I don't understand why processing by tree edges is correct.

For example 2 3

1 1 1 2 2 1 2

1 2 2 3 Would fail when processing by tree edges, but why this input is incorrect?

Ice coloring: Could someone explain how following given tree topology — colors it correctly? Which part of problem guarantees it?

For example not following tree, just processing by tree vertex index, would fail on test 143 that is a custom hack.

Yep, thanks for confirmation.

In problem B, if I have pole of height 10 at 0 and pole of height 3 at 100. Suggested solution is iterating all and adding areas — 100 + 109 = 209. But it's not optimal, optimal is 9 + 109 + 118. What am I missing?

+43

Placed 500th, what a luck.

On rekStrange problem, 9 years ago
0

Ah, I see n distinct numbers, not n pairs that got distinct numbers.

On rekStrange problem, 9 years ago
0

For each pair find a positive difference. Find all divisors of that difference — add them to global hash-table. Iterate numbers from 1 to infinity and check presence in hash-table. If it's not in hash-table, that's your k.

If you have pair 1 & 7, difference is 6, divisors are 1,2,3,6 (added to hash-table) — so the smallest k is 4. Keep adding divisors for other pairs and then find smallest k.

Complexity O(n * sqrt(m)), where n — number of pairs and m is 10^9 in your case.

On root8950What is wrong in this logic?, 10 years ago
0

No, algorithm starts with binary search (0 to 10^6). For each value (carry weight per bear) to test — graph is constructed, where each node represents how many bears can go through that edge (capacity/weight -> integral number of bears). Running Max-Flow on such graph will return number of bears can go through. Back to binary search, you need to find carry weight per bear, that yields more or equal number of bears you need.

Operation x & (x — 1) sets rightmost 1 to 0. As powers of 2 have only one 1 — it can be used to check them.

Test 76 on C is a winner. Who's idea was to add it?

On danilka.proCodeforces Round #330, 10 years ago
0

Because it's a different compiler, different cpu or different OS? Never cast floating values to integers, if you must — add 0.5 before casting. But in this case — you can just multiply by 10 until you get that power.

On danilka.proCodeforces Round #330, 10 years ago
0

Casting double value of power to integer and expecting correct conversion? What about values as 999.999999, wouldn't it evaluate to int value 999?

On danilka.proCodeforces Round #330, 10 years ago
0

For warrior, I was removing first or last element (from remaining set), for archer second or second last element — depending on gap sizes at front & back. But I couldn't solve ties when front & back gaps were equal (it would require to iterate through all existing elements, to resolve ties), was getting WA on 6th pretest.

On danilka.proCodeforces Round #330, 10 years ago
+7

You're missing 12 more red figures

If you have found diameter, you should have started on one end of it and finished on another. It's in case you have used 2xDFS or 2xBFS to find diameter.

Omg it started on 9AM not on 10AM local time.

I'm the victim of 5 3 5, staircase was a killer.

Multi-level bfs? One (dfs or bfs) to determine what unvisited bosses he can visit next. Another bfs to find least number of bosses to visit.

On SteamTurbineCodeforces Round #180, 13 years ago
0

Hi, I can't find out why my fishes problem exceeded time limit. http://www.codeforces.com/contest/298/submission/3573315 Can someone with a keen eye spot what's wrong? Thx in advance.

Is there a way to get full test case data?

Confirmed. Same code in C++ worked under 360ms in the worst case. It's not first time when Mono compiler let's me down.

I have used shuffle before sort, as Dalex proposed elsewhere, and it ran under 140ms in C#.

On HolkinPVCodeforces Beta Round #72, 15 years ago
0
Hey, I have solved C but on pretest No 1 I got WA, even on local machine it worked. I'm using C#. My code is here http://codepaste.net/pzyu3k. On first test case locally I get correct answer but on Codeforces site I get 0 -1 -1 -1. Is it BinarySearch broken on Mono or something else? Can anyone point it out?
On Alex_KPRCodeforces Beta Round #69, 15 years ago
0
Thx, I got it now.

There may be few possibilities for min diff, I just took one with min value. That's really omg. :B

got AC after considering this
On Alex_KPRCodeforces Beta Round #69, 15 years ago
0
Hi,
DIV 2 - C

Test case
5
Troll likes Dracul
Anka likes Chapay
Cleo likes Anka
Chapay likes Cleo
Snowy likes Hexadecimal
222 400 400

why the answer is 89 5

what im getting is 222(Snowy), 400(Anka, Chapy, Cleo), 400(Hexadecimal, Troll, Dracul) => diff 89, likes 4.

what's wrong?