← 返回 anthropic 的题目列表Find All Possible Recipes from Given Supplies
类型:online_judge
Problem: Find All Possible Recipes from Given Supplies
You are given:
recipes[i]: the name of the i-th recipe;
ingredients[i]: all ingredients required to make recipes[i];
supplies: the basic ingredients you initially have.
Each ingredient name may be either:
a basic supply, or
the name of another recipe.
A recipe can be made if all of its required ingredients are available. Once a recipe is made, it also becomes an available ingredient and may be used to make other recipes.
Return all recipes that can eventually be made, in the original order of recipes.
Input Format
The standard input contains 3 lines, each in JSON format:
Line 1: a string array recipes;
Line 2: a 2D string array ingredients;
Line 3: a string array supplies.
Output Format
Output a JSON string array containing all recipes that can be made, in the original order of recipes.
Constraints
1 <= len(recipes) <= 10^5
len(ingredients) == len(recipes)
The total number of ingredient entries is at most 2 * 10^5
Names contain only lowercase English letters and have length in [1, 20]
All recipe names are unique
Example
Input:
["bread","sandwich"]
[["yeast","flour"],["bread","meat"]]
["yeast","flour","meat"]
Output:
["bread","sandwich"]
Example
Input
["bread"]
[["yeast","flour"]]
["yeast","flour","corn"]
Output
["bread"]