1371 问题 A: Intermediary

时间限制: 1s 内存限制: 128MB 提交: 35 解决: 18
题目描述
It is widely known that any two strangers can get to know each other through at most six other people. Now let’s prove this.

In the country Intermediary Conducts Personal Communications (ICPC), there are up to n (2<=n<=100) ordinary people conveniently numbered from 0 to n-1. They don’t know each other, or, in other words, they are strangers. The only way they can communicate with each other is through the government, which, in fact, is an intermediary agency. The government consists of up to m (1<=m<=9) employees conveniently numbered from 0 to m-1. Suppose employee z can introduce person x to person y at a cost of d dollars. If this is the first time in a day that employee z introduce one person to another, he will only require d dollars. For the second time, he will require d dollars plus extra e dollars as his tip. For the third time and more, he will require d dollars plus extra f dollars. He is not dared to require any more than that since the strange country is somewhat democratic. And if person x is able to communicate with person t and person t is able to communicate with person y, then person t is always willing to transfer messages from person x to person y, at no charge. Of course, the intermediary fees are all paid by person x. Notice that employee z being able to introduce person x to person y doesn’t mean he can introduce person y to person x.

Now person 0 has to send a message to person n-1 in one day. If all employees have just started to work, what is the minimum cost for person 0?
输入
For each test case, the first line contains three integers, n, m and q, where q is the number of intermediary relationships and q is at most 10,000. The second line has m integers, each indicating the value e of every employee, in the range [0, 100]. The third line has m integers too, each indicating the value f of every employee, in the range [e, 200]. The next q lines each contains four integers, x, y, z and d, indicating that employee z can introduce person x to person y requiring d dollars, where 1<=d<=200. There is a blank line after each test case.

Proceed to the end of file.
输出
For each test case, print one integer on a single line, giving the minimum cost. If it is impossible, print -1.
样例输入
3 2 2
1 1
2 2
0 1 0 1
1 2 1 2

5 1 4
1
2
0 1 0 1
1 2 0 1
2 3 0 1
3 4 0 1
样例输出
3
9
提示

零基础的同学可以先学习基础,教程见:  C语言教程C++教程编译器教程数据结构教程Python教程单片机教程

视频教学见视频网课

比赛公告

题号:1371,1372,1373,1374,1375,1376,1377,1378,1379,1380

点击上方导航栏的训练,点击题库,寻找题号即可找到对应题目,比赛结束后,请通过训练->题库->寻找对应题目的方式做题

因为不确定因素太多,就不再安排大家轮流讲题了,大家做不出题可以在测试结束后去题库找对应的题目看题解,希望大家自觉练习,认真练习,考核测试会采取不同与现在测试的方式,两个月后综合测试成绩不达标者会退出实验室,希望大家认真对待