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 ...
随机推荐
- 抛弃阿里云,中国用户购买海外VPS的五个理由
王掌柜在过去的五年多时间里,折腾过不少vps品牌,最开始玩的是一年一百多块钱的香港虚拟主机,后来业务量大了,开始折腾国内的小鸟云.阿里云.腾讯云.电信云.百度云主机,国外的linode\interse ...
- windows cmd启动heritrix
首先下载heritrix-1.14.4.zip文件,可以在http://sourceforge.net/projects/archive-crawler/files/heritrix3/下载.下载后解 ...
- Sublime Text学习笔记
1.快捷键(Key Bindings) Preferences -> Key Bindings ->Default 会打开一个配置文件,里面全是配置信息 2.代码片段(Snippe ...
- FbinstTool(U盘启动盘制作工具) v1.606 免费绿色版
软件名称: FbinstTool(U盘启动盘制作工具) v1.606 免费绿色版软件语言: 简体中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP / W ...
- 菲菲更名宝贝(批量更名软件) v8.0 绿色版
软件名称: 菲菲更名宝贝(批量更名软件)软件语言: 简体中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 1.5MB图片预览: 软件简介:菲 ...
- matlab里的nargin
nargin是用来判断输入变量个数的函数,这样就可以针对不同的情况执行不同的功能.
- stm32按键识别
刚写了一个关于stm32单片机的按键识别的程序.目的,同时识别多个按键,并且不浪费cpu的时间. 关于去抖动,以前以为是在按键的时候,手会抖动.通过程序验证,这个确实是误解.这个应该是防止意外干扰.以 ...
- FZU 1502 Letter Deletion
最长公共子序列. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #i ...
- MFC连接Access讲解(3合1) .
方法一: 1.首先,要用#import语句来引用支持ADO的组件类型库(*.tlb),其中类型库可以作为可执行程序(DLL.EXE等)的一部分被定位在其自身程序中的附属资源里,如:被定位在msado1 ...
- LeetCode OJ 226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was ...