N cities named with numbers 1 ... N are connected with one-way roads. Each road has two parameters associated with it : the road length and the toll that needs to be paid for the road (expressed in the number of coins).
Bob and Alice used to live in the city 1. After noticing that Alice was cheating in the card game they liked to play, Bob broke up with her and decided to move away - to the city N. He wants to get there as quickly as possible, but he is short on cash.

We want to help Bob to find the shortest path from the city 1 to the city N that he can afford with the amount of money he has.
Input
The first line of the input contains the integer K, 0 <= K <= 10000, maximum number of coins that Bob can spend on his way.
The second line contains the integer N, 2 <= N <= 100, the total number of cities.

The third line contains the integer R, 1 <= R <= 10000, the total number of roads.

Each of the following R lines describes one road by specifying integers S, D, L and T separated by single blank characters :
• S is the source city, 1 <= S <= N
• D is the destination city, 1 <= D <= N
• L is the road length, 1 <= L <= 100
• T is the toll (expressed in the number of coins), 0 <= T <=100

Notice that different roads may have the same source and destination cities.
Output
The first and the only line of the output should contain the total length of the shortest path from the city 1 to the city N whose total toll is less than or equal K coins.
If such path does not exist, only number -1 should be written to the output.
Sample Input
5
6 7
1 2 2 3
2 4 3 3
3 4 2 4
1 3 4 1
4 6 2 1
3 5 2 0
5 4 3 2


Sample Output
11


先来了解一下这道题吧，这个题的大致意思很容易明白，就是


head[f[i].u] = i;                //存储这次出现的位置 

通过判断点u到v所用的花费和之前的花费之和 是否超出本有的资金，再决定是否进入队列中。


for(int i = head[now.u]; i ; i = f[i].next)
//找到所有和now.s相连的点
if(now.cost + f[i].cost <= K)   //注意这里面的i表示的是第几条边
{
tmp.cost = now.cost + f[i].cost;
tmp.u = f[i].v;
tmp.s = now.s + f[i].l;
Q.push(tmp);
}

本题中，首先用结构体存入R条道路中，所给出的信息。然后再用一个结构体保存在寻找过程中所走的最短路口，以及所需要的花费

struct note
{
int u,v,l,cost;    //地点u -> v, 距离  花费
int next;

}f[10010];

struct node
{
int u,s,cost;
friend bool operator < (node a,node b)
{
return a.s > b.s;
}
};



#include<stdio.h>
#include<queue>
#include<string.h>
#include<iostream>
using namespace std;

int N,K,R;

struct note
{
int u,v,l,cost;
int next;
}f[10010];

struct node
{
int u,s,cost;
friend bool operator < (node a,node b)
{
return a.s > b.s;
}
};

int bfs()
{
priority_queue<node>Q;
node now,tmp;
now.u = 1;
now.s = 0;
now.cost = 0;
Q.push(now);
while(!Q.empty())
{
now = Q.top();
Q.pop();
if(now.u == N)
return now.s;
for(int i = head[now.u]; i ; i = f[i].next)        //找到所有和now.s相连的点
if(now.cost + f[i].cost <= K)                //注意这里面的i表示的是第几条边
{
tmp.cost = now.cost + f[i].cost;
tmp.u = f[i].v;
tmp.s = now.s + f[i].l;
Q.push(tmp);
}
}
return -1;
}

int main()
{
while(~scanf("%d%d%d",&K,&N,&R))
{