Tasks

Task 1

Trick or treat!

On a windy Halloween night, a little boy named Domi set off with a red bucket in hand, excited to collect chocolates.

Before he left, his parents gave him a few rules.

“You can collect as much candy as you like,” said his mom, “but later, you may only eat two pieces.

The rest will be saved for later.”

“And,” added his dad with a mischievous smile, “I'll be the one to decide just how heavy those two pieces can be.”

 

Task:

Domi has a bucket of chocolates, each with an associated weight, and he wants to select two of them to achieve the allowed weight.

Given a list of integers where each number represents the weight of a chocolate and an integer representing the target weight, you must find the index of the first two chocolates that add up to exactly the target weight.

 

Example 1

Input

[4, 5, 6, 2]

8

 

Output

2, 3

 

Example 2

(if no combination is found)

Input

[1, 2, 3, 4]

9

 

Output

null

 

Example 3

(In the case that there is more than one possible combination, select the combination whose second chocolate appears first in the list.)

 

Input

[1, 2, 3, 4]

5

 

Output

1, 2

(it could also be 0, 3 but there is a combination earlier)

 

Your task:

Read input file and into the field with the answer, enter :

  • The resulting values on separated rows
  • At the end paste the source code of your program.

Input file

Click HERE to download the input file.

Answer

Click HERE to download the answer.

 

Correct answer:

For each correctly solved case - 0.1 point.

For all correct answers bonus - 0.1 point

Task 2

Night of the Living Edges

At midnight on All Hallows’ Eve, spectral bridges connect the frightening houses. Some form harmless paths… but once a circle closes, the spirits inside can never rest.
Count the cursed networks before daybreak reaches the night.

On All Hallows’ Eve, N haunted houses (numbered 1 … N) are linked by ghostly corridors that only ever appear.

Each corridor is undirected and, once created, never disappears.

 

You will receive Q events of two kinds:

  • + u v — a new corridor appears between houses u and v
  • ? — the witch asks:

How many connected components currently contain at least one cycle?

(in other words, how many components are not trees)

 

A connected component is called cursed if it contains at least one simple cycle.

 

Input

  • The first line contains two integers N Q
  • (1 ≤ N ≤ 2·10⁵, 1 ≤ Q ≤ 2·10⁵)
  • N - number of nodes
  • Each of the next Q lines is one event in one of these forms:
    • + u v ( 1 ≤ u,v ≤ N, u ≠ v )
    • ?

 

Corridors are undirected.

If the same pair u v is added more than once, treat each addition as an extra edge — it only matters whether a component has at least one cycle.

 

Output

For every ? event, output one integer —

the current number of cursed components.

 

Example 1

 

Input

5 7

+ 1 2

+ 2 3

?

+ 3 1

?

+ 4 5

?

 

Output

0

1

1

 

Explanation:

After 1–2 and 2–3, component {1,2,3} is a tree → 0.

Adding 3–1 creates a cycle → 1 cursed component.

Adding 4–5 doesn’t change that → still 1.

 

Example 2

 

4 8

+ 1 2

+ 2 3

+ 3 4

?

+ 2 4

?

+ 1 3

?

 

Output

0

1

1

 

Logic checks out:

  • After the first three edges: path → 0 cursed.
  • Adding 2–4 creates a cycle → 1 cursed.
  • Adding 1–3 keeps it cyclic → still 1.

 

Constraints & Implementation Tips

  • Up to 2·10⁵ operations → use efficient I/O.
  • 1-indexed vertices.
  • Self-loops (u = v) can be ignored safely.

 

Your task:

Read input file and into the field with the answer, enter :

  • the resulting values.
  • at the end paste the source code of your program.

 

Input file

Click HERE to download the input file.

 

Answer

Click HERE to download the answer.

Points for Correct answer Source Code
Round 2 2 1

 

Bonus points for Quick and correct answer
Round 2 6 5 4 3 2 1

 

Correct answer:

For each correct position - 0.7 point (rounded 0.05 high)

Task 3

Haunted mansion

Story

Tom has received a map of haunted mansion rooms. Each room has a number (1..N).

Room with number 1 may or may not be the main entrance.

On the map, the rooms are connected by secret passages or so called “creepy corridors”. Tom knows which rooms have passages to which other rooms (e.g., room 1 has passage to rooms 2 and 3).

No secret passage leads into the main entrance.

A spooky event has occurred: some rooms have mysteriously vanished from the mansion.

Tom needs to find out how many different rooms can still be reached from the main entrance, using the secret passages. He knows which of the rooms have disappeared. He also knows that the main entrance is the only one accessible from the outside.

Because the spell was cast by a “muggle”, there is one more obstacle to solving Toms task. Each room, that has been connected to at least two other vanished rooms, has disappeared also. Luckily, this “spell mishap” has not spread on further. In other words, “additionally” vanished rooms have not caused more rooms to vanish.

Important:

Once Tom reaches a room via a secret passage, he cannot travel back to the previously visited room. In other words, the passages form a one-way path with no circular routes.
 

Input:

The first line contains a number: the total number of rooms (rooms are numbered from 1 to N). Room 1 may or may not be the main entrance.

The second line contains the number of the vanished rooms (M).

The next N lines each describe a room and its secret passages. The first number is the room itself, followed by numbers of rooms it has passage to. They are separated by commas.

For example, 1,4,5 means room 1 has passages to rooms 4 and 5.

2,8,9,11 means room 2 has passages to rooms 8, 9, and 11, etc.

If a room has no passages, the line contains only its number.

The next M lines each contain a number: these are the room numbers of the rooms that have vanished in the first round.
 

Output:

Output must contain three lines. Each line contains a single number.

  1. What is the room number of the main entrance?
  2. How many more rooms have additionally disappeared due to the “poorly” casted spell?
  3. How many rooms (including the main one) can be reached after the vanishings?

 

 Example 1:

Input:

4
1
1,2,3
3,4
2,3
4
3

Output:

1
0
2

 

 

 

 

 

Example 2:

 

Input:

6
2
4,1,5
2
5
6,2
3,4,6
1
1
5

Output:

3
1
3

 

 

 

 

 

 

 

 

Your task:

Read input file and into the field with the answer, enter :

  • The resulting values on separated rows
  • At the end paste the source code of your program.

Input file:

  Click HERE to download the input file.

 

Answer

Click HERE to download the answer.

Points for Correct answer Source Code
Round 3 3 1

 

Bonus points for Quick and correct answer
Round 3 7 6 5 4 3 2 1

 

Correct answer:

Room number of the main entrance : 1 point

Number of additionally vanished rooms : 1 point

Total reachable rooms (including the main one) : 1 point

 

Task 4 

Midnight Spirits

Story: 

At midnight, the spirits appeared in the streets, their pale shapes drifting through the shadows.

Domi knew he had to find a way home—one that kept him as far from danger as possible.

 

************

Task:

 

The map to Domi's home is represented by a maze of cells, where each cell has a numeric value indicating the danger level of the cell.

 

You must find the safest path (i.e., the one with the lowest total danger value) from the top-left corner to the bottom-right corner of the matrix.

 

In this challenge, you can only move right or down (you cannot move back or diagonally), and you must calculate the total danger level of the safest path.

 

The map is represented by an n x m matrix where each cell is a positive number representing the danger level of that cell on the map.

 

And you have to return the total danger value of the safest path from the top-left corner (position [0][0]) to the bottom-right corner (position [n-1][m-1]) and the safest path coordinations.

 

************

Example:

Input:

 

map = [

[1, 3, 1],

[1, 5, 1],

  [4, 2, 1],

]

 

Output:

7

[0, 0]

[0, 1]

[0, 2]

[1, 2]

[2, 2]

 

************

Your task:

Read input file and into the field with the answer, enter :

  • The resulting values for each case according output in example
  • At the end paste the source code of your program.

Input file:

Click HERE to download the input file.

 

Answer:

Click HERE to download the answer.

Points for

Correct answer

Source Code

 

Bonus points for

Quick and correct answer

Round 4

4

1

 

Round 4

8

7

6

5

4

3

2

1

 

Correct answer:

Total danger value of the safest path : 0,2 points

Safest path coordinations : 0,3 points

----------

Total for every case : 0,5 points