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 ...
随机推荐
- LeetCode OJ 122. Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- 依赖跟踪如何工作的(How dependency tracking works)
这一块主要是理论的讲解,本人刚接触这块不久,就不敢翻译了,请参见园子里其他人的现有文章 http://www.cnblogs.com/TomXu/archive/2011/11/22/2256820. ...
- CSSd的优先级别
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- AutoTile 自动拼接 番外篇(自动融合技术)
http://pan.baidu.com/s/1dDQyfSl 密码:ttud 先睹为快吧. 之后 还差一个 智能替换 技术.
- android之ViewStub的使用
转自http://blog.csdn.net/hitlion2008/article/details/6737537 在开发应用程序的时候,经常会遇到这样的情况,会在运行时动态根据条件来决定显示哪个V ...
- Servie之前台Service
public class MyService extends Service { public static final String TAG = "MyService"; pri ...
- 使用 VirtualBox 虚拟机在电脑上运行 Android 4.0 系统,让电脑瞬间变安卓平板
Ref: http://www.iplaysoft.com/android-v4-ics-for-virtualbox.html 随着 Android 手机的各种软件应用越来越多,很多没有购买的朋友都 ...
- SSH登录很慢问题的解决方法
用ssh连其他linux机器,会等待10-30秒才有提示输入密码.严重影响工作效率. 关闭ssh的gssapi认证 用ssh -v user@server 可以看到登录时有如下信息: debug1: ...
- Industry Engineer
IE:有两种,一种是系统方面的,对全厂的物流设计,依据产量做人力估算,机台,设备,手工具的估算等,一种是配合产能提升做制造的改善,以及SOP(Standard Operation Procedure: ...
- mysql grant授权
MySQL 赋予用户权限命令的简单格式可概括为: grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利. grant sele ...