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 ...
随机推荐
- mysql的字符串处理函数
一.简明总结ASCII(char) 返回字符的ASCII码值BIT_LENGTH(str) 返回字符串的比特长度CONCAT(s1,s2…,sn) 将s1,s2…,sn连接成字符串CONCAT_WS( ...
- NOIP2010-普及组复赛-第二题-接水问题
题目描述 Description 学校里有一个水房,水房里一共装有 m 个龙头可供同学们打开水,每个龙头每秒钟的供水量相等,均为 1. 现在有 n 名同学准备接水,他们的初始接水顺序已经确定.将这些 ...
- MATLAB将变量存储到EXCEL
代码如下: d = {'Time','Temperature'; 12,98; 13,99; 14,97}; xlswrite('testdata2.xls', d, 1, 'E1') 运行如下:
- yii2 windows 安装
Yii是一个高性能的,适用于开发WEB2.0应用的PHP框架. Yii自带了丰富的功能 ,包括MVC,DAO/ActiveRecord,I18N/L10N,缓存,身份验证和基于角色的访问控制,脚手架, ...
- php 分页类(3)
<?php class Page { private $total; //总记录 private $pagesize; //每页显示多少条 private $limit; //limit pri ...
- 从Map、JSONObject取不存在键值对时的异常情况
1.在Map中取不存在的键值对时不会报异常,只会返回null. @Test public void testMap() { Map<String, Object> map = new Ha ...
- hadoop pig入门总结
在这里贴一个pig源码的分析,做pig很长时间没做笔记,不包含任何细节,以后有机会再说吧 http://blackproof.iteye.com/blog/1769219 hadoop pig入门总结 ...
- Android自动测试之monkeyrunner工具
monkeyrunner工具 前言: 最近开始研究Android自动化测试方法,对其中的一些工具.方法和框架做了一些简单的整理,其中包括 android测试框架.CTS.Monkey.Monkeyr ...
- IntelliJ IDEA 部署远程服务
今天产品遇到个本地无法重现,服务器上却出现的 Bug. 想起来 IDEA 有远程调试的功能就拿来用用. 教程如下: 1. 创建 tomcat service 2. 填入服务器的 IP 和端口 3. 确 ...
- 第一天学习oc用xcode做的一个加减乘除 圆的面积计算
#import <Foundation/Foundation.h> //这是oc的框架 @interface jisuan : NSObject //申明一个jisuan这样的类 并继 ...