{"trustable":true,"sections":[{"title":"Description","value":{"format":"MD","content":"In university, each student must select some courses from many options to achieve a certain number of credits. Some courses must be taken before others; for example, advanced mathematics must always be taken before other courses. Now there are $N$ courses, each with a certain number of credits, and each course may have one or no direct prerequisite (if course a is a prerequisite for course b, then course a must be completed before course b can be taken). A student needs to choose $M$ courses from these options; what is the maximum number of credits he can obtain?"}},{"title":"Input","value":{"format":"MD","content":"The first line contains two integers $N$ and $M$ separated by a space. ( $1 \\leq N \\leq 300$ , $1 \\leq M \\leq 300$ )\n\nThe next $N$ lines, the $I+1$-th line contains two integers $k_i $ and $s_i$, $k_i$ representing the direct prerequisite of the I-th course, and $s_i$ representing the credits of the I-th course. If $k_i\u003d0$ indicates that there is no direct prerequisite ( $1 \\leq {k_i} \\leq N$ , $1 \\leq {s_i} \\leq 20$ )."}},{"title":"Output","value":{"format":"MD","content":"There is only one line, the maximum score for selecting $M$ courses."}},{"title":"Sample 1","value":{"format":"MD","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e7 4\n2 2\n0 1\n0 4\n2 1\n7 1\n7 6\n2 2\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e13\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}}]}