hdu1535—Invitation Cards(spfa)
来源:互联网 发布:欧特克软件侵权案件 编辑:程序博客网 时间:2024/05/20 14:44
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1535
Invitation Cards
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 4143 Accepted Submission(s): 1887
Problem 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
题目大意:求起点到其它点的最短距离和+其他点到起点的最短距离和
解题思路:正向建图跑次spfa,反向建图跑次spfa
#include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <queue>#include <set>#include <string>#include <stack>#include <algorithm>#include <map>using namespace std; typedef long long ull;const int N = 1000010;const int M = 108;const int INF = 0x3fffffff;const double Pi = acos(-1.0);struct edge{int u,v,len;}e[N];struct Edge{int node,len;Edge*next;}m_edge[N];Edge*head[N];int Ecnt,dist[N],vis[N];void init(){Ecnt = 0;fill( head , head+N , (Edge*)0 );}void mkEdge( int a , int b , int c ){m_edge[Ecnt].node = b;m_edge[Ecnt].len = c;m_edge[Ecnt].next = head[a];head[a] = m_edge+Ecnt++;}void spfa(){fill( dist , dist+N , INF );fill( vis , vis+N , 0 );queue<int>point;point.push(1);vis[1] = 1;dist[1] = 0;while( !point.empty() ){int s = point.front();point.pop();vis[s] = 0;for( Edge*p = head[s] ; p ; p = p->next ){int t = p->node;if( dist[t] > dist[s]+p->len ){dist[t] = dist[s]+p->len;if( !vis[t] ){point.push(t);vis[t] = 1;}}}}}int main(){int T,P,Q;scanf("%d",&T);while( T-- ){scanf("%d%d",&P,&Q);for( int i = 0 ; i < Q ; ++i ){scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].len);}int ans = 0;init();for( int i = 0 ; i < Q ; ++i ){mkEdge( e[i].u , e[i].v , e[i].len );}spfa();for( int i = 1 ; i <= P ; ++i ){ans += dist[i];}init();for( int i = 0 ; i < Q ; ++i ){mkEdge( e[i].v , e[i].u , e[i].len );}spfa();for( int i = 1 ; i <= P ; ++i ){ans += dist[i];}printf("%d\n",ans);}return 0;}
阅读全文
0 0
- hdu1535—Invitation Cards(spfa)
- HDU1535:Invitation Cards(SPFA)
- poj1511||hdu1535 Invitation Cards spfa
- hdu1535 Invitation Cards(spfa+反向建图)
- HDU1535~Invitation Cards(spfa+邻接表反转)
- HDU1535 Invitation Cards(最短路,spfa)
- hdu1535——Invitation Cards
- HDU1535 Invitation Cards(最短路)
- HDU1535:Invitation Cards(最短路)
- POJ1511 Invitation Cards(SPFA)
- POJ-1511(Invitation Cards )——spfa+邻接表
- poj1511——Invitation Cards(SPFA+邻接表)
- poj 1511 Invitation Cards (spfa)
- hdu 1535 Invitation Cards(spfa)
- hdu 1535 Invitation Cards(SPFA)
- POJ 1511 Invitation Cards (spfa)
- POJ1511 Invitation Cards(SPFA+逆图)
- POJ 1511 Invitation Cards(SPFA)
- 移植oprofile到dm365
- javascript基础
- Normalization on conv4_3 in SSD
- uml系列(八)——部署图与构件图
- 电商秒杀场景的解决策略与具体实现方案
- hdu1535—Invitation Cards(spfa)
- Android通过滑动实现Activity跳转(手势识别器应用)
- 信号处理第一课:向量的空间与子空间
- 软件工程师职业发展与晋升通道
- tomcat win 经验
- unexpected char: '@' [from cn.mani123.domain.Order where product = cn.mani123.domain.Product@11d48a7
- opencv2 hsv分离
- VPN编写总结
- uml系列(七)——交互图