{"trustable":false,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n #problem-body \u003e pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv\u003e \n \u003cp\u003e The traffic network in a country consists of N cities (labeled with integers 1 to N) and N-1 roads connecting the cities. There is a unique path between each pair of different cities.\u003c/p\u003e \n \u003cp\u003e \u003cbr\u003e Because of the many years of lazy maintenance the roads are pretty damaged and for each road two numbers A and B are known – the integer A represents the current time (in seconds) needed to travel along the road, and the integer B represents the smallest possible time (in seconds) needed to travel along this road if we repair all the damage.\u003c/p\u003e \n \u003cp\u003e \u003cbr\u003e We want to invest a certain amount of money into road repair. For a particular road, the result will be proportional to the amount of invested money. For each euro invested in some road, the time needed to travel along that road will be reduced by one second (the amount of money invested in some road has to be an integer). The travel time cannot be reduced beyond the smallest possible time B described above.\u003c/p\u003e \n \u003cp\u003e \u003cbr\u003e We are given a certain amount of money. We want to distribute this money along different roads in such a way that the time needed to travel from the city 1 to the most distant city (after all the repairs) is as small as possible.\u0026nbsp;Most distant city refers to the city to which it takes the most time to get to, rather than deepest in the tree.\u003c/p\u003e \n \u003cp\u003e \u003cbr\u003e Write a program that will find this smallest time.\u003c/p\u003e \n \u003ch3\u003e Input\u003c/h3\u003e \n \u003cp\u003e The first line of input contains two integers N and K, 2 ≤ N ≤ 100 000, 0 ≤ K ≤ 1 000 000, the number of cities and the total amount of money (in \u003cspan\u003eeuros\u003c/span\u003e).\u003c/p\u003e \n \u003cp\u003e \u003cbr\u003e Each of the next N-1 lines contains four integers X, Y, A and B, 0 ≤ B ≤ A ≤ 10 000. It means that there is a road between cities X and Y, with the numbers A and B representing the current time and the minimum time as described above.\u003c/p\u003e \n \u003ch3\u003e Output\u003c/h3\u003e \n \u003cp\u003e The first and only line of output should contain a single integer – the minimum time from the task description.\u003c/p\u003e \n \u003ch3\u003e Sample\u003c/h3\u003e \n \u003cpre\u003e\r\n\tinput \r\n\u0026nbsp;\r\n3 200 \r\n1 2 200 100 \r\n2 3 450 250 \r\n\u0026nbsp;\r\noutput \r\n\u0026nbsp;\r\n450\r\n\r\ninput \r\n\u0026nbsp;\r\n5 11 \r\n1 2 10 5 \r\n1 3 3 2 \r\n1 4 9 6 \r\n3 5 7 3 \r\n\u0026nbsp;\r\noutput \r\n\u0026nbsp;\r\n6\r\n\r\ninput \r\n\u0026nbsp;\r\n11 12 \r\n1 2 7 5 \r\n1 3 20 15 \r\n2 4 10 8 \r\n2 5 5 3 \r\n2 6 6 2 \r\n4 7 3 0 \r\n4 8 7 2 \r\n5 9 8 4 \r\n5 10 9 8 \r\n5 11 6 5 \r\n\u0026nbsp;\r\noutput \r\n\u0026nbsp;\r\n17\u003c/pre\u003e \n \u003cp\u003e \u0026nbsp;\u003c/p\u003e \n\u003c/div\u003e"}}]}