Tap here to switch tabs
Problem
Submissions

Problem: Maximize Value of Function in a Ball Passing Game

Try to solve the Maximize Value of Function in a Ball Passing Game problem.

Statement

You are given a 00 indexed integer array receiver of length nn and an integer k.

There are nn players numbered from 00 to n−1n - 1 taking part in a ball passing game. When a player x holds the ball, they pass it directly to player receiver[x].

The game starts by selecting any player i (0≤i<n0 \le i < n) to hold the ball initially, which sets the starting score to i. The ball is then passed exactly k times. Whenever the ball is passed to player receiver[x], the value receiver[x] is added to the current score.

Return the maximum possible score achievable after k passes by choosing the optimal starting player.

Constraints:

  • 1≤1 \le receiver.length ==n≤105== n \le 10^5

  • 0≤0 \le receiver[i] ≤n−1\le n - 1

  • 1≤1 \le k ≤1010\le 10^{10}

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximize Value of Function in a Ball Passing Game

Try to solve the Maximize Value of Function in a Ball Passing Game problem.

Statement

You are given a 00 indexed integer array receiver of length nn and an integer k.

There are nn players numbered from 00 to n−1n - 1 taking part in a ball passing game. When a player x holds the ball, they pass it directly to player receiver[x].

The game starts by selecting any player i (0≤i<n0 \le i < n) to hold the ball initially, which sets the starting score to i. The ball is then passed exactly k times. Whenever the ball is passed to player receiver[x], the value receiver[x] is added to the current score.

Return the maximum possible score achievable after k passes by choosing the optimal starting player.

Constraints:

  • 1≤1 \le receiver.length ==n≤105== n \le 10^5

  • 0≤0 \le receiver[i] ≤n−1\le n - 1

  • 1≤1 \le k ≤1010\le 10^{10}