The TransCompilator

Solved LeetCode program · 880 of 1,000

#1203 · Sort Items by Groups Respecting Dependencies

Hard Depth-First Search chunk-18.md

Original English source

Keep a shared group holding -1, -1, 1, 0, 0, 1, 0, and -1.

Keep a shared homes holding 2, 3, 1, 0, 0, 1, 0, and 4.

Keep a shared withins as an empty list of whole numbers. Keep a shared needs as an empty list of whole numbers. Keep a shared taken as an empty list of whole numbers. Keep a shared ranked as an empty list of whole numbers. Keep a shared sizes as an empty list of whole numbers. Keep a shared ordernext as an empty list of whole numbers. Keep a shared orderneed as an empty list of whole numbers. Keep a shared chosen of 0. Keep a shared solos holding 0, 1, and 7.

For every spot from 0 to 63.
Place 0 into withins.

For every spot from 0 to 7.
Place 0 into needs. Place 0 into taken.

For every spot from 0 to 15.
Place 0 into ranked.

For every spot from 0 to 1.
Place 0 into sizes.

For every spot from 0 to 24.
Place 0 into ordernext.

For every spot from 0 to 4.
Place 0 into orderneed.

The links is a list of 6, 1, 5, 2, 6, 3, 3, 4, 6, and 4.

For every edge from 0 to 4.
The before is item (edge times 2) of links. The after is item (edge times 2 plus 1) of links. The one is item before of group. The two is item after of group. If one is two and one is not -1, set item (before times 8 plus after) of withins to 1, set item after of needs to item after of needs plus 1.

For every item from 0 to 7.
The team is item item of group. If team is not -1, set item team of sizes to item team of sizes plus 1.

To choose from team (a whole number). Set chosen to -1.
For every item from 0 to 7.
If item item of group is team and item item of taken is 0 and item item of needs is 0 and chosen is -1, set chosen to item, stop.

To release from pick (a whole number).
For every other from 0 to 7.
If item (pick times 8 plus other) of withins is 1, set item other of needs to item other of needs minus 1.

To arrange from team (a whole number). Set count to 0.
For every slot from 0 to 7.
If count is less than item team of sizes.
Choose from team. The pick is chosen.
If pick is at least 0.
Set item (team times 8 plus count) of ranked to pick. Add 1 to count. Set item pick of taken to 1. Release from pick.

To attach from first (a whole number) with second (a whole number). If item (first times 5 plus second) of ordernext is 1, return. Set item (first times 5 plus second) of ordernext to 1. Increase item second of orderneed by 1.

For every edge from 0 to 4.
The before is item (edge times 2) of links. The after is item (edge times 2 plus 1) of links. The one is item before of homes. The two is item after of homes. If one is not two, Attach from one with two.

Arrange from 0. Arrange from 1.

The queue is an empty list of whole numbers. The order is an empty list of whole numbers. The head is 0. The followed is 0.
For every block from 0 to 4.
If item block of orderneed is 0, Place block into queue, add 1 to followed.

Repeat while head is less than followed.
The node is item head of queue. Add 1 to head. Place node into order.
For every next from 0 to 4.
If item (node times 5 plus next) of ordernext is 1.
Decrease item next of orderneed by 1. If item next of orderneed is 0, Place next into queue, add 1 to followed.

To showgroup from block (a whole number). The count is item block of sizes. The bottom is block times 8.
For every within from 0 to count minus 1.
The spot is bottom plus within. Show item spot of ranked.

To showone from block (a whole number). The solo is block minus 2. Show item solo of solos.

To showblock from block (a whole number). If block is less than 2, Showgroup from block. If block is at least 2, Showone from block.

For every spot from 0 to 4.
The block is item spot of order. Showblock from block.

Open in Playground Browse all 1,000 problems

Expected stdout

6
3
4
5
2
0
7
1