Banner Home Page Web Contests Problems Ranklist Status Statistics
FightŁĄ

Paid Roads

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 8   Accepted Submission(s) : 3
Problem Description

A network of m roads connects N cities (numbered from 1 to N). There may be more than one road connecting one city with another. Some of the roads are paid. There are two ways to pay for travel on a paid road i from city ai to city bi:

The payment is Pi in the first case and Ri in the second case.

Write a program to find a minimal-cost route from the city 1 to the city N.

 

Input
<p>The first line of the input contains the values of <b>N</b> and <b>m</b>. Each of the following <b>m</b> lines describes one road by specifying the values of <b>a<sub>i</sub></b>, <b>b<sub>i</sub></b>, <b>c<sub>i</sub></b>, <b>P<sub>i</sub></b>, <b>R<sub>i</sub></b> (1 ≤ <b>i </b>≤ <b>m</b>). Adjacent values on the same line are separated by one or more spaces. All values are integers, 1 ≤ <b>m, N</b> ≤ 10, 0 ≤ <b>P<sub>i</sub></b> , <b>R<sub>i</sub></b> ≤ 100, <b>P</b><sub>i</sub> ≤ <b>R<sub>i</sub></b> (1 ≤ <b>i </b>≤ <b>m</b>).</p>
 

Output
<p>The first and only line of the file must contain the minimal possible cost of a trip from the city 1 to the city <b>N</b>. If the trip is not possible for any reason, the line must contain the word ‘<b>impossible</b>’.</p>
 

Sample Input
4 5 1 2 1 10 10 2 3 1 30 50 3 4 3 80 80 2 1 2 10 10 1 3 2 10 50
 

Sample Output
110
 

Source
PKU
 

Statistic | Submit | Back