hdu 1535 Invitation Cards(SPFA)
Invitation Cards
Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other)
Total Submission(s) : 28 Accepted Submission(s) : 14
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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
Output
Sample Input
2
2 2
1 2 13
2 1 33
4 6
1 2 10
2 1 60
1 3 20
3 4 10
2 4 5
4 1 50
Sample Output
46
210
/*
这题一直Memory limit Exceeded
开的变量太大了,
再开一个vector<node> s;就不行
而开三个int类型[1000002]的数组就可以
总之以后,容器不能用太多。。。
*/
#include <iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<queue>
using namespace std; bool vis[];
struct node
{
int num,d;
node(int a,int b){num=a; d=b;}
};
vector<node> s[];
int dis[];
int i,j,n,m,t;
const int inf=0x7fffffff;
int x[],y[],d[]; void spfa()
{
int i,j;
for(i=;i<=n;i++) {dis[i]=inf;vis[i]=;}
vis[]=;
dis[]=;
queue<int>Q;
Q.push();
while(!Q.empty())
{
int p=Q.front();
Q.pop();
vis[p]=;
for(i=;i<s[p].size();i++)
{
if(dis[s[p][i].num]<=dis[p]+s[p][i].d) continue;
dis[s[p][i].num]=dis[p]+s[p][i].d;
if(!vis[s[p][i].num])
{
Q.push(s[p][i].num);
vis[s[p][i].num]=;
}
}
}
return;
} int main()
{
scanf("%d",&t);
for(;t>;t--)
{
scanf("%d%d",&n,&m);
for(i=;i<=n;i++) s[i].clear();
for(i=;i<=m;i++)
{
scanf("%d%d%d",&x[i],&y[i],&d[i]);
s[x[i]].push_back(node(y[i],d[i]));
} int sum=; spfa();
for(i=;i<=n;i++) sum+=dis[i]; for(i=;i<=n;i++)s[i].clear();
for(i=;i<=m;i++) s[y[i]].push_back(node(x[i],d[i]));
spfa();
for(i=;i<=n;i++) sum+=dis[i];
printf("%d\n",sum);
}
return ;
}
hdu 1535 Invitation Cards(SPFA)的更多相关文章
- [HDU 1535]Invitation Cards[SPFA反向思维]
题意: (欧洲人自己写的题面就是不一样啊...各种吐槽...果断还是看晕了) 有向图, 有个源叫CCS, 求从CCS到其他所有点的最短路之和, 以及从其他所有点到CCS的最短路之和. 思路: 返回的时 ...
- HDU 1535 Invitation Cards(SPFA,及其优化)
题意: 有编号1-P的站点, 有Q条公交车路线,公交车路线只从一个起点站直接到达终点站,是单向的,每条路线有它自己的车费. 有P个人早上从1出发,他们要到达每一个公交站点, 然后到了晚上再返回点1. ...
- HDU 1535 Invitation Cards(最短路 spfa)
题目链接: 传送门 Invitation Cards Time Limit: 5000MS Memory Limit: 32768 K Description In the age of te ...
- HDU - 1535 Invitation Cards 前向星SPFA
Invitation Cards In the age of television, not many people attend theater performances. Antique Come ...
- hdu 1535 Invitation Cards(spfa)
Invitation Cards Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 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 (POJ 1511)
两次SPFA. 求 来 和 回 的最短路之和. 用Dijkstra+邻接矩阵确实好写+方便交换.可是这个有1000000个点.矩阵开不了. d1[]为 1~N 的最短路. 将全部边的 邻点 交换. d ...
- 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 ...
随机推荐
- 关于NLog的target和Layout
这个没啥好说的,都是用别人的东西,看文档就行了,写的很详细. https://github.com/NLog/NLog/wiki/Configuration-file https://github.c ...
- 2016NEFU集训第n+3场 E - New Reform
Description Berland has n cities connected by m bidirectional roads. No road connects a city to itse ...
- (转载)CSS中zoom:1的作用
CSS中zoom:1的作用兼容IE6.IE7.IE8浏览器,经常会遇到一些问题,可以使用zoom:1来解决,有如下作用:触发IE浏览器的haslayout解决ie下的浮动,margin重叠等一些问题. ...
- shell笔记-local、export用法
local一般用于局部变量声明,多在在函数内部使用. 1. Shell脚本中定义的变量是global的,其作用域从被定义的地方开始,到shell结束或被显示删除的地方为止. 2. ...
- dist-upgrade
http://www.linuxserve.com/2015/06/how-to-enable-automatic-login-on-debian.html http://www.cyberciti. ...
- UVALive 7077 Little Zu Chongzhi's Triangles (有序序列和三角形的关系)
这个题--我上来就给读错了,我以为最后是一个三角形,一条边可以由多个小棒组成,所以想到了状态压缩各种各样的东西,最后成功了--结果发现样例过不了,三条黑线就在我的脑袋上挂着,改正了以后我发现N非常小, ...
- RIDE的使用
在RIDE中,CTRL + R 自动打开report.html , CTRL + L 自动打开 log.html
- keybd_event 对应表
Option Explicit Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bSc ...
- MFC下DLL编程(图解)
MFC下DLL编程(图解) DLL(Dynamic Link Library,动态链接库)是微软公司为Windows和OS/2操作系统设计一种供应用程序在运行时调用的共享函数库.DLL是应用程序的一种 ...
- SELECT TOP 1 * FROM是什么意思
SELECT TOP 1 * FROM的含义: 1.select为命令动词,含义为执行数据查询操作: 2.top 1子句含义为查询结果只显示首条记录: 3.*子句表示查询结果包括数据源中的所有字段: ...