hdu 1535 Invitation Cards(spfa)
Invitation Cards
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3129 Accepted Submission(s):
1456
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.
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.
amount of money to be paid each day by ACM for the travel costs of its
volunteers.
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <queue>
- #define M 1000010
- #define inf 0x3f3f3f3f
- using namespace std;
- struct node
- {
- int now,to,w;
- } e[M];
- int first[M],nexts[M];
- int n,m,dis[M],vis[M];
- void init()
- {
- int i,j;
- for(i=; i<=m; i++)
- first[i]=nexts[i]=-;
- for(i=; i<m; i++)
- {
- scanf("%d%d%d",&e[i].now,&e[i].to,&e[i].w);
- nexts[i]=first[e[i].now]; //spfa()算法
- first[e[i].now]=i;
- }
- }
- void spfa(int src,int flag)
- {
- int i,j;
- for(i=; i<=n; i++)
- dis[i]=inf;
- dis[src]=;
- for(i=; i<=n; i++)
- vis[i]=;
- queue<int> q;
- q.push(src);
- while(!q.empty())
- {
- src=q.front();
- q.pop();
- vis[src]=;
- for(i=first[src]; i!=-; i=nexts[i])
- {
- int to=(flag?e[i].to:e[i].now);
- if(dis[to]>dis[src]+e[i].w) //每次比较更新
- {
- dis[to]=dis[src]+e[i].w;
- if(!vis[to])
- {
- vis[to]=;
- q.push(to);
- }
- }
- }
- }
- }
- void set_map()
- {
- int i,j;
- for(i=; i<=m; i++)
- first[i]=nexts[i]=-;
- for(i=; i<m; i++)
- {
- int now=e[i].now;
- int to=e[i].to;
- nexts[i]=first[to];
- first[to]=i;
- }
- }
- int main()
- {
- int T,i,j,sum;
- scanf("%d",&T);
- while(T--)
- {
- sum=;
- scanf("%d%d",&n,&m);
- init();
- spfa(,);
- for(i=; i<=n; i++) //先将1到每个车站的最小花费加起来
- sum+=dis[i];
- set_map(); //重置图
- spfa(,);
- for(i=; i<=n; i++) //将所有点到1的最小花费加起来
- sum+=dis[i];
- printf("%d\n",sum);
- }
- return ;
- }
hdu 1535 Invitation Cards(spfa)的更多相关文章
- HDU 1535 Invitation Cards(最短路 spfa)
题目链接: 传送门 Invitation Cards Time Limit: 5000MS Memory Limit: 32768 K Description In the age of te ...
- HDU 1535 Invitation Cards (POJ 1511)
两次SPFA. 求 来 和 回 的最短路之和. 用Dijkstra+邻接矩阵确实好写+方便交换.可是这个有1000000个点.矩阵开不了. d1[]为 1~N 的最短路. 将全部边的 邻点 交换. d ...
- hdu 1535 Invitation Cards(SPFA)
Invitation Cards Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other) T ...
- HDU - 1535 Invitation Cards 前向星SPFA
Invitation Cards In the age of television, not many people attend theater performances. Antique Come ...
- HDU 1535 Invitation Cards(逆向思维+邻接表+优先队列的Dijkstra算法)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1535 Problem Description In the age of television, n ...
- HDU 1535 Invitation Cards (最短路)
题目链接 Problem Description In the age of television, not many people attend theater performances. Anti ...
- hdu 1535 Invitation Cards (最短路径)
Invitation Cards Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 1535 Invitation Cards(SPFA,及其优化)
题意: 有编号1-P的站点, 有Q条公交车路线,公交车路线只从一个起点站直接到达终点站,是单向的,每条路线有它自己的车费. 有P个人早上从1出发,他们要到达每一个公交站点, 然后到了晚上再返回点1. ...
- [HDU 1535]Invitation Cards[SPFA反向思维]
题意: (欧洲人自己写的题面就是不一样啊...各种吐槽...果断还是看晕了) 有向图, 有个源叫CCS, 求从CCS到其他所有点的最短路之和, 以及从其他所有点到CCS的最短路之和. 思路: 返回的时 ...
随机推荐
- HR招聘_(六)_招聘方法论(面试环节·面试方法)
面试方法:常用行为面试和压力面试 行为面试法 定义: 通过要求面试对象描述其过去某项工作或者生活经历的具体情况来了解面试对象各方面素质特征的方法.行为面试法的基本假设是:一个人过去的行为可以预测这个人 ...
- vue渲染学生信息
渲染学生信息 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- 可复用且高度解耦的iOS用户统计实现
http://www.cocoachina.com/ios/20160421/15912.html 本文为投稿文章,作者:编程小翁(简书) 用户统计 用户行为统计(User Behavior Stat ...
- Future Maker | 领跑亚太 进击的阿里云数据库
7月31日,阿里云马来西亚峰会在吉隆坡召开,阿里巴巴集团副总裁.阿里云智能数据库事业部总裁李飞飞在演讲中表示:“作为亚太地区第一的云服务提供商,阿里云数据库已为多家马来西亚知名企业提供技术支持,助力企 ...
- JavaScript-- 函数既是函数又是对象
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【转载】【python】python练手项目
入门篇 1.Python - Python 图片转字符画 50 行 Python 代码完成图片转字符画小工具. <img src="https://pic3.zhimg.com ...
- Nginx教程(二) Nginx虚拟主机配置 (转)
Nginx教程(二) Nginx虚拟主机配置 1 虚拟主机管理 1.1 Nginx管理虚拟主机 虚拟主机使用的是特殊的软硬件技术,它把一台运行在因特网上的服务器主机分成一台台“虚拟”的主机,每台虚拟主 ...
- Limboy:自学 iOS 开发的一些经验
不知不觉作为 iOS 开发也有两年多的时间了,记得当初看到 OC 的语法时,愣是被吓了回去,隔了好久才重新耐下心去啃一啃.啃了一阵,觉得大概有了点概念,看到 Cocoa 那么多的 Class,又懵了, ...
- Array操作的方法
//concat连接数组连接一个或多个数组 //var a = [1,2,3]; //var c=[4,5] //var b = a.concat(c); //console.log(b); //jo ...
- 一条SQL完成跨数据库实例Join查询
背景 随着业务复杂程度的提高.数据规模的增长,越来越多的公司选择对其在线业务数据库进行垂直或水平拆分,甚至选择不同的数据库类型以满足其业务需求.原本在同一数据库实例里就能实现的SQL查询,现在需要跨多 ...