NEU 1006 Intermediary

1006: Intermediary

时间限制: 1 Sec  内存限制: 128 MB
提交: 261  解决: 25
[提交][状态][讨论版]

题目描述

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

提示

来源

辽宁省赛2010

题目描述:

一个城市有n个人编号从0到n-1,m个中介编号从0到m-1,大家互相都不认识,必须通过中介来传递信息,不同中介在不同人之间传递信息收费不同(单向的,比如0号中介可以把1号居民的信息传递给2号居民,反过来不一定成立),每个中介在第一次传递信息不收取小费,第二次收取小费e,第三次及其以上收取小费f(不同的中介收费不同)。

在这种情况下,0号居民想向n-1号居民传递一则信息,问最小花费多少。

输入:

多测试点,每个点的输入格式如下

第一行n,m,q,表示居民数,中介数,和中介可以达成的传递种数

第二行m个数代表每个中介的小费e

第三行m个数代表每个中介的小费f

第四行到第3+q行每行四个数字x,y,z,d,表示中介z可以传递居民x的信息给居民y,花费为d(没有加上小费)。

输出:

一行,一个数字,代表0号居民向n-1号居民传递一则信息的最小花费。

思路:暴力搜索加最优化剪枝

时间: 2024-10-10 08:25:59

NEU 1006 Intermediary的相关文章

PAT 1006 换个格式输出 C语言

让我们用字母B来表示"百".字母S表示"十",用"12...n"来表示个位数字n(<10),换个格式来输出任一个不超过3位的正整数.例如234应该被输出为BBSSS1234,因为它有2个"百".3个"十".以及个位的4. 输入格式:每个测试输入包含1个测试用例,给出正整数n(<1000). 输出格式:每个测试用例的输出占一行,用规定的格式输出n. 输入样例1: 234 输出样例1: BBSSS1

TypeError: Error #1006: value 不是函数。

1.错误原因 TypeError: Error #1006: value 不是函数. at BasicChart/dataFunc()[E:\Flash Builder\Map\src\BasicChart.mxml:68] at mx.charts.chartClasses::Series/cacheDefaultValues()[E:\dev\4.0.0\frameworks\projects\datavisualization\src\mx\charts\chartClasses\Seri

解决openstack “failed to connect to server (code: 1006)”故障一例

openstack版本环境:ocata 安装完成ocata版本后,新建主机实例后,通过管理端进入主机实例的控制台时,报错:"failed to connect to server (code: 1006)" 解决思路: 1.检查日志文件,通过日志寻找原因. tail -f /var/log/nova/nova-novncproxy.log 发现连接5900时出现"Name or service not known" 2017-05-17 17:01:43.994 7

问题 1006: C语言程序设计教程(第三版)课后习题5.4

/******************************************************************** @file Main.cpp @date 2017-05-07 @author Zoro_Tiger @brief 问题 1006: C语言程序设计教程(第三版)课后习题5.4 http://www.dotcpp.com/oj/problem1006.html *************************************************

生理周期,POJ(1006)

题目链接:http://poj.org/problem?id=1006 解题报告: 1.枚举天数的时候可以根据前面的结果直接跳过一些错误的答案. ///三个周期是23,28,33, #include <stdio.h> int main() { int p,e,i,d,Case=1; while(scanf("%d%d%d%d",&p,&e,&i,&d),p!=-1) { int t1=p%23,t2=e%28,t3=i%33;///三个周期

solution for 1006 中国剩余定理

一.要求 http://poj.org/problem?id=1006 Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 124113   Accepted: 39154 Description Some people believe that there are three cycles in a person's life that start the day he or she is born.

【BZOJ】1006 神奇的国度

[解析]完美消除序列+染色 [Analysis] 由题知他们的关系构成一个弦图,所以求出完美消除序列一定是成立的. 先求出,然后根据序列来染色,尽可能染小的. 其实时间戳那里用个线段树+二分好像也不错,甚至树状数组都可以,因为元素的变化是单调的... 在此给出证明: 首先进行以下的定义: 团数:最大团的大小. 色数:染色最少用的颜色. ∵团中颜色要两两不同 ∴团数<=色数 ∵我们对序列的染色共染了t种颜色且这样的染色是合法的,但是暂时不能保证最少. ∴t>=色数. 又∵我们的染色方法是贪心的,

1006. 换个格式输出整数

1006. 换个格式输出整数 (15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 让我们用字母B来表示“百”.字母S表示“十”,用“12...n”来表示个位数字n(<10),换个格式来输出任一个不超过3位的正整数.例如234应该被输出为BBSSS1234,因为它有2个“百”.3个“十”.以及个位的4. 输入格式:每个测试输入包含1个测试用例,给出正整数n(<1000). 输出格式:每个测试用例的输出占一

NEU 1458 方格取数(网络流之费用流)

题目地址:NEU 1458 跟杭电上的那两个方格取数不太一样..这个可以重复,但是取和的时候只能加一次.建图思路基本一会就出来.同样的拆点,只不过这题需要再拆个边,其中一条费用0,另一条费用为那个点处的值.流量都限制为1.然后剩下的都跟杭电上的那两个差不多了.因为把数组开小了WA了好几发..(我前面居然还专门检查了一下数组大小,居然当时还认为没开小...对自己无语..) 代码如下: #include <iostream> #include <stdio.h> #include &l