#include #include #include #include #define ld long double using namespace std; int main() { int n; cin >> n; vector recipes; unordered_map accessibility; for (int i = 0; i < n; ++i) { string recipe; cin >> recipe; recipes.push_back(recipe); int s; cin >> s; unordered_map end; int beginnerTime = 0, expertTime = 0; for (int j = 0; j < s; ++j) { string step; int t, d; cin >> step >> t >> d; beginnerTime += t; int depEnd = 0; for (int k = 0; k < d; ++k) { string dep; cin >> dep; if (depEnd < end[dep]) depEnd = end[dep]; } end[step] = t + depEnd; if (expertTime < t + depEnd) expertTime = t + depEnd; } accessibility[recipe] = (double) beginnerTime / (double) expertTime; } sort(recipes.begin(), recipes.end(), [&](auto a, auto b) { return accessibility[a] < accessibility[b]; }); for (auto recipe : recipes) { cout << recipe << endl; } }