Invitation Cards

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1588    Accepted Submission(s): 714

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.

 
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
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
 
Source
 
Recommend
LL   |   We have carefully selected several similar problems for you:  1317 1531 1546 1384 1245 
 
 //1125MS    41076K    1434 B    G++
/* 其实开始让我做我是拒绝的,不能叫我做我马上做,我得先试一下。不然加了特效搞得好像很容易那样,结果群众却做不出来,
我会被批的。 题意:
有编号1~P个点,有Q条单向路,求 1到其他P-1个点 + 其他P-1个点到1 的最短路线 最短路径:
首先数据比较大,用spfa比较靠谱。其实,第一个很明显以1为源点进行一次spfa就出来了,问题是第二个的求法,
首先遍历P-1个点是会TLE的,所以要转一下思维,就是逆向思维。把原来的路线全都反向再建图(即把u->v变成v->u),
在来一次源点为1的spfa就得出解了。 */
#include<iostream>
#include<vector>
#include<queue>
#define N 1000005
#define inf 0x7ffffff
using namespace std;
struct node{
int v,w;
node(int a,int b){
v=a;w=b;
}
};
vector<node>V[N];
int d[N];
int vis[N];
int p,q;
int a[N],b[N],w[N]; //记录路线信息
void spfa(int s) //spfa模板
{
for(int i=;i<=p;i++) d[i]=inf;
memset(vis,,sizeof(vis));
queue<int>Q;
Q.push(s);
d[s]=;
while(!Q.empty()){
int u=Q.front();
Q.pop();
vis[u]=;
int n0=V[u].size();
for(int i=;i<n0;i++){
int v=V[u][i].v;
int w=V[u][i].w;
if(d[v]>d[u]+w){
d[v]=d[u]+w;
if(!vis[v]){
Q.push(v);
vis[v]=;
}
}
}
}
}
int main(void)
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&p,&q);
for(int i=;i<=p;i++) V[i].clear();
int ans=;
for(int i=;i<q;i++){ //正向建图
scanf("%d%d%d",&a[i],&b[i],&w[i]);
V[a[i]].push_back(node(b[i],w[i]));
}
spfa();
for(int i=;i<=p;i++) ans+=d[i];
for(int i=;i<=p;i++) V[i].clear();
for(int i=;i<q;i++) //反向建图
V[b[i]].push_back(node(a[i],w[i]));
spfa();
for(int i=;i<=p;i++) ans+=d[i];
printf("%d\n",ans);
}
return ;
}

hdu 1535 Invitation Cards (最短路径)的更多相关文章

  1. HDU 1535 Invitation Cards(逆向思维+邻接表+优先队列的Dijkstra算法)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1535 Problem Description In the age of television, n ...

  2. HDU 1535 Invitation Cards(最短路 spfa)

    题目链接: 传送门 Invitation Cards Time Limit: 5000MS     Memory Limit: 32768 K Description In the age of te ...

  3. HDU 1535 Invitation Cards (POJ 1511)

    两次SPFA. 求 来 和 回 的最短路之和. 用Dijkstra+邻接矩阵确实好写+方便交换.可是这个有1000000个点.矩阵开不了. d1[]为 1~N 的最短路. 将全部边的 邻点 交换. d ...

  4. hdu 1535 Invitation Cards(SPFA)

    Invitation Cards Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) T ...

  5. HDU 1535 Invitation Cards (最短路)

    题目链接 Problem Description In the age of television, not many people attend theater performances. Anti ...

  6. HDU - 1535 Invitation Cards 前向星SPFA

    Invitation Cards In the age of television, not many people attend theater performances. Antique Come ...

  7. hdu 1535 Invitation Cards(spfa)

    Invitation Cards Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  8. hdu 1535 Invitation Cards

    http://acm.hdu.edu.cn/showproblem.php?pid=1535 这道题两遍spfa,第一遍sfpa之后,重新建图,所有的边逆向建边,再一次spfa就可以了. #inclu ...

  9. [HDU 1535]Invitation Cards[SPFA反向思维]

    题意: (欧洲人自己写的题面就是不一样啊...各种吐槽...果断还是看晕了) 有向图, 有个源叫CCS, 求从CCS到其他所有点的最短路之和, 以及从其他所有点到CCS的最短路之和. 思路: 返回的时 ...

随机推荐

  1. JSP自定义标记

    JSP自定义标记(可以使JSP网页变得简洁并且易于维护) 一.自定义标记的方式 1.实现接口Tag 2.继承类TagSupport或BodyTagSupport   二.JSP自定义标记的生命周期 1 ...

  2. HJ浇花

    题目描述 HJ养了很多花(99999999999999999999999999999999999盆),并且喜欢把它们排成一排,编号0~999999999999999999999999999999999 ...

  3. 洛谷P1829 [国家集训队]Crash的数字表格 / JZPTAB(莫比乌斯反演)

    题目背景 提示:原 P1829 半数集问题 已经迁移至 P1028 数的计算 题目描述 今天的数学课上,Crash小朋友学习了最小公倍数(Least Common Multiple).对于两个正整数a ...

  4. HDU 2047 EOF牛肉串

    水到不想整理,线性DP #include <algorithm> #include <iostream> #include <cstring> #include & ...

  5. LArea 微信端 地址选择

    最近做到一个项目,微信端的商城需要地址选择功能 在百度上看了,采用LArea.js....下载实例,在移动端模拟器上运行是比较好的, 在微信上模拟后出现很多问题, 1,出现undefined 都定义正 ...

  6. 路由器基础配置之单臂路由实现vlan间通信

    我们将以上面的拓扑图开始进行配置,目的为设置单臂路由实现vlan间通信,设置4个vlan,pc0,1,2为vlan10 pc3,4,5为vlan20:pc6,7,8为vlan30:server0,1为 ...

  7. redis安装与简单使用

    第一步 新建一个文件 第二步 利用winscrp软件从本机上传redis的压缩包到linux新建的rdtar目录 第三步   cd rdtar 第四步   解压  tar zxvf redis-2+t ...

  8. mysql的一些相关的命令(2013-05-05-bd 写的日志迁移

    cmd中连接:mysql -u用户名 -p用户密码 (注:u与root可以不用加空格,其它也一样)断开:exit (回车) --建立数据库creata database 数据库名;--切换到数据库下工 ...

  9. 1016-06-首页20-封装工具条---UITableView控件距离顶部的间距问题----cell选中时的背景颜色设置

    一.设置UITableView里面的顶部 cell 距离顶部的间距的三种方式: 方法 1. 直接设置: self.tableView.contentInset = UIEdgeInsetsMake(H ...

  10. Lighting System Design UVA - 11400 动态规划

    题目:题目链接 思路:简单的动态规划问题,先把灯泡按照电压从小到大排序.设s[i]为前i种灯泡的总数量(即L值之和),d[i]为灯 泡1-i的最小开销,则d[i] = min{d[j] + (s[i] ...