[最短路spfa]pku1511-Invitation Cards
来源:互联网 发布:java构造其作用原理 编辑:程序博客网 时间:2024/05/28 20:19
http://acm.pku.edu.cn/JudgeOnline/problem?id=1511
Invitation Cards
Time Limit: 8000MS Memory Limit: 262144KTotal Submissions: 5784 Accepted: 1616
Description
In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, most of all, Antique Comedies. They have printed invitation cards with all the necessary information and with the programme. A lot of students were hired to distribute these invitations among the people. Each student volunteer has assigned exactly one bus stop and he or she stays there the whole day and gives invitation to people travelling by bus. A special course was taken where students learned how to influence people and what is the difference between influencing and robbery.
The transport system is very special: all lines are unidirectional and connect exactly two stops. Buses leave the originating stop with passangers each half an hour. After reaching the destination stop they return empty to the originating stop, where they wait until the next full half an hour, e.g. X:00 or X:30, where 'X' denotes the hour. The fee for transport between two stops is given by special tables and is payable on the spot. The lines are planned in such a way, that each round trip (i.e. a journey starting and finishing at the same stop) passes through a Central Checkpoint Stop (CCS) where each passenger has to pass a thorough check including body scan.
All the ACM student members leave the CCS each morning. Each volunteer is to move to one predetermined stop to invite passengers. There are as many volunteers as stops. At the end of the day, all students travel back to CCS. You are to write a computer program that helps ACM to minimize the amount of money to pay every day for the transport of their employees.
The transport system is very special: all lines are unidirectional and connect exactly two stops. Buses leave the originating stop with passangers each half an hour. After reaching the destination stop they return empty to the originating stop, where they wait until the next full half an hour, e.g. X:00 or X:30, where 'X' denotes the hour. The fee for transport between two stops is given by special tables and is payable on the spot. The lines are planned in such a way, that each round trip (i.e. a journey starting and finishing at the same stop) passes through a Central Checkpoint Stop (CCS) where each passenger has to pass a thorough check including body scan.
All the ACM student members leave the CCS each morning. Each volunteer is to move to one predetermined stop to invite passengers. There are as many volunteers as stops. At the end of the day, all students travel back to CCS. You are to write a computer program that helps ACM to minimize the amount of money to pay every day for the transport of their employees.
Input
The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case begins with a line containing exactly two integers P and Q, 1 <= P,Q <= 1000000. P is the number of stops including CCS and Q the number of bus lines. Then there are Q lines, each describing one bus line. Each of the lines contains exactly three numbers - the originating stop, the destination stop and the price. The CCS is designated by number 1. Prices are positive integers the sum of which is smaller than 1000000000. You can also assume it is always possible to get from any stop to any other stop.
Output
For each case, print one line containing the minimum amount of money to be paid each day by ACM for the travel costs of its volunteers.
Sample Input
22 21 2 132 1 334 61 2 102 1 601 3 203 4 102 4 54 1 50
Sample Output
46210
Source
Central Europe 1998
题目大意:给出一个有向图和起点,求其他所有点到这个点的最短路和这个点到其他点的最短路的总和。
分析:因为数据规模很大,所以用dijkstra会超时,考虑到边不是特别多,所以选择用spfa。如果枚举每个点作为起点求它到1的距离的话,效率太低,会超时。其实,只要把图中的边都反过来,再求一次单源最短路就可以了。
我用的是静态链表。
codes:
- [最短路spfa]pku1511-Invitation Cards
- 【图论】【最短路】 pku1511 Invitation Cards
- PKU1511(Invitation Cards)最短路径-邻接表+SPFA算法
- poj 1511 Invitation Cards(spfa最短路)
- POJ 1511 Invitation Cards 最短路SPFA
- HDOJ 1535 Invitation Cards 【最短路 SPFA】
- HDU1535 Invitation Cards(最短路,spfa)
- POJ1511 Invitation Cards [最短路,dijstra+heap,spfa]
- POJ 1511 Invitation Cards 求来回最短路(spfa)
- poj 1511&&zoj 2008 Invitation Cards 最短路+SPFA
- POJ 1511 Invitation Cards(spfa最短路)
- POJ 1511Invitation Cards SPFA最短路问题
- hdu 1535 Invitation Cards 最短路spfa+逆向建图
- POJ 1511 Invitation Cards【来回最短路+SPFA】
- poj 1511 Invitation Cards 最短路SPFA(模板题)
- POJ 1511 Invitation Cards(最短路spfa算法)
- POJ 1511 Invitation Cards(最短路spfa算法)
- POJ1511 Invitation Cards 【最短路】
- 要毕业了
- Struts的工作流程
- 纯js绘制饼图(基于wz_jsgraphics.js)
- 嵌入式程序员必须知道的16个问题(C语言方面)
- Setting Database Control Preferences
- [最短路spfa]pku1511-Invitation Cards
- 电
- MFC类型
- 将Excel文件数据导入数据到SQL数据库中
- 李开复创新工场办公环境首度曝光 网友称太寒酸(图)
- struts2+spring+hibernate+json+jquery+flexigrid开发笔记-封装视图层增删改查
- 中国Internet与网民生活的变迁
- 负向零宽断言 备忘录
- 百度划词查询小工具