아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Cookbook Composition

시간 제한2초메모리 제한2048 MB

요약
레시피마다 임계 경로 시간(전문가)과 전체 단계 시간 합(초보자)을 구한 뒤 초보자 대 전문가 비율로 정렬합니다.
난이도

보통10점 중 5점

유형
위상 정렬, 시뮬레이션, 정렬
정답자
아직 제출이 없습니다

문제

The world-famous chef Gordon Oliver is composing a new cookbook called "Becoming A Perfect Chef". He has a list of recipes that he wants to publish in the cookbook. Each recipe is in the form of a list of steps, where every step might depend on some previous steps (meaning a step cannot be started until all its dependencies have finished), and expected time per step.

Gordon knows that, as an expert chef, he can multitask and do as many tasks simultaneously as needed. Meanwhile, a beginner can do one task at a time, so they need to execute them sequentially. He would like to order the recipes for the cookbook by accessibility, where the lowest beginner timeexpert time\frac{\text{beginner time}}{\text{expert time}} ratio recipes come first.

As an example, consider the first sample case. For the oven dish, an expert chef like Gordon Oliver can prepare the tomatoes, eggplants, and sauce all at the same time (with the sauce taking the longest: 55 time), and followed by arranging (11) and baking (3030) the dish, this takes 5+1+30=365+1+30=36 time. On the other hand, a beginner needs 2+2+5+1+30=402+2+5+1+30=40 time to make the oven dish. This makes the accessibility ratio of the oven dish 40/36≈1.1140/36\approx 1.11. The accessibility ratio of the ice cream is 11 (because beginner and expert chefs both require 5+5+5+240=2555+5+5+240=255 time to prepare it), so it comes before the oven dish in the cookbook.

입력

The input consists of:

  • One line with an integer nn (2≤n≤5002\leq n\leq 500), the number of recipes.

  • Then, for every recipe:

    • One line with the name of the recipe and an integer ss (1≤s≤501\leq s\leq 50), the number of steps in the recipe.
    • ss lines, one for every step in the recipe, with the step name, an integer tt (1≤t≤1061\leq t\leq 10^6), the step duration, an integer dd (0≤d≤490\leq d\leq 49), the number of dependencies, followed by a list of step names that this step depends on. A step only appears once all the steps that it depends on have been listed.

The recipe and step names consist of at most 1010 English lowercase letters (a-z).

The recipe names are unique and the step names are unique per recipe.

출력

Output the names of the recipes in the cookbook, ordered by accessibility.

If there are multiple valid solutions, you may output any one of them.

예제3

  1. 예제 1

    입력
    2
    ovendish 5
    tomatoes 2 0
    eggplants 2 0
    sauce 5 0
    arrange 1 3 tomatoes eggplants sauce
    bake 30 1 arrange
    icecream 4
    mix 5 0
    heat 5 1 mix
    churn 5 1 heat
    freeze 240 1 churn
    
    예상 출력
    icecream
    ovendish
    
  2. 예제 2

    입력
    2
    recipea 4
    stepa 5 0
    stepb 5 1 stepa
    stepc 2 0
    stepd 2 1 stepc
    recipeb 4
    stepa 1 0
    stepb 2 1 stepa
    stepc 2 1 stepa
    stepd 1 2 stepb stepc
    
    예상 출력
    recipea
    recipeb
    
  3. 예제 3

    입력
    2
    recipea 2
    stepa 2 0
    stepb 2 1 stepa
    recipeb 2
    stepa 5 0
    stepb 5 1 stepa
    
    예상 출력
    recipeb
    recipea