Invitation Cards

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

Total Submission(s): 2173    Accepted Submission(s): 1056

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 

pid=1217" target="_blank">1217 1531 1548 1546




最短路, 先按题意建图然后求出最短路,然后建立反图求出最短路,最后把权值加起来即可了

#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = 1000010;
const int M = 1000010;
const int inf = 0x3f3f3f3f;
typedef pair<int, int> pi; struct node
{
int weight;
int next;
int to;
}edge[M], edge2[M]; int head[N], head2[N];
int tot1, tot2;
int dist[N]; void addedge(int from, int to, int weight)
{
edge[tot1].weight = weight;
edge[tot1].to = to;
edge[tot1].next = head[from];
head[from] = tot1++;
} void readdedge(int from, int to, int weight)
{
edge2[tot2].weight = weight;
edge2[tot2].to = to;
edge2[tot2].next = head2[from];
head2[from] = tot2++;
} void dijkstra(int v0)
{
memset ( dist, inf, sizeof(dist) );
dist[v0] = 0;
priority_queue< pi, vector<pi>, greater<pi> > qu;
while ( !qu.empty() )
{
qu.pop();
}
qu.push(make_pair( dist[v0], v0) );
while ( !qu.empty() )
{
pi tmp = qu.top();
int u = tmp.second;
int d = tmp.first;
qu.pop();
for (int i = head[u]; ~i; i = edge[i].next)
{
int v = edge[i].to;
if (dist[v] > d + edge[i].weight)
{
dist[v] = d + edge[i].weight;
qu.push( make_pair(dist[v], v) );
}
}
}
} void dijkstra2(int v0)
{
memset ( dist, inf, sizeof(dist) );
dist[v0] = 0;
priority_queue< pi, vector<pi>, greater<pi> > qu;
while ( !qu.empty() )
{
qu.pop();
}
qu.push(make_pair( dist[v0], v0) );
while ( !qu.empty() )
{
pi tmp = qu.top();
int u = tmp.second;
int d = tmp.first;
qu.pop();
for (int i = head2[u]; ~i; i = edge2[i].next)
{
int v = edge2[i].to;
if (dist[v] > d + edge2[i].weight)
{
dist[v] = d + edge2[i].weight;
qu.push( make_pair(dist[v], v) );
}
}
}
} int main()
{
int t;
int n, m, u, v, w;
scanf("%d", &t);
while (t--)
{
scanf("%d%d", &n, &m);
memset ( head, -1, sizeof(head) );
memset (head2, -1, sizeof(head2) );
tot1 = tot2 = 0;
for (int i = 0; i < m; ++i)
{
scanf("%d%d%d", &u, &v, &w);
addedge(u, v, w);
readdedge(v, u, w);
}
__int64 ans = 0;
dijkstra(1);
for (int i = 2; i <= n; ++i)
{
ans += dist[i];
}
dijkstra2(1);
for (int i = 2; i <= n; ++i)
{
ans += dist[i];
}
printf("%I64d\n", ans);
}
return 0;
}

hdu1535——Invitation Cards的更多相关文章

  1. HDU1535——Invitation Cards(最短路径:SPAF算法+dijkstra算法)

    Invitation Cards DescriptionIn the age of television, not many people attend theater performances. A ...

  2. hdu1535 Invitation Cards 最短路

    有一张图,若干人要从不同的点到同一个中间点,再返回,求总费用最小 中间点到各个点最小费用是普通的最短路 各个点到中间点最小费用其实就是将所有路径反向建边之后中间点到各个点的最小费用,同样用最短路就可以 ...

  3. POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)

    POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...

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

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

  5. POJ 1511 Invitation Cards (spfa的邻接表)

    Invitation Cards Time Limit : 16000/8000ms (Java/Other)   Memory Limit : 524288/262144K (Java/Other) ...

  6. POJ 1511 Invitation Cards (最短路spfa)

    Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...

  7. Poj 1511 Invitation Cards(spfa)

    Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 24460 Accepted: 8091 De ...

  8. Invitation Cards(邻接表+逆向建图+SPFA)

    Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 17538   Accepted: 5721 Description In ...

  9. [POJ] 1511 Invitation Cards

    Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 18198   Accepted: 596 ...

随机推荐

  1. iframe和response.sendRedirect()跳转到父页面的问题

    在项目中,因为为了给页面分层次,就使用了 内嵌iframe 的分了三个框.在子页面进行操作的时候,如果session超时,就要被拦截器拦截重新回到首页进行登录,但是在sub页 面 ,进行操作的时候,如 ...

  2. eclipse无法导入Android工程的解决办法

    我以前在windows平台下写的android源代码无法通过import"existing project into workspace"导入到mac的eclipse中,直接搜不见 ...

  3. cocurrent包 原子性数据类型

    22. 原子性布尔 AtomicBoolean AtomicBoolean 类为我们提供了一个可以用原子方式进行读和写的布尔值,它还拥有一些先进的原子性操作,比如 compareAndSet().At ...

  4. VMware报错“原因: 未能锁定文件”,打开失败

    原文:http://jingyan.baidu.com/article/425e69e6bf64dbbe15fc16fe.html VMware打开复制的虚拟机,报错“原因: 未能锁定文件”,打开失败 ...

  5. [转]WCF RESTful service and WebGrid in ASP.NET MVC 5

    使用WebClient调用WCF服务 流程:从View获取实体类-->序列化-->写入内存流中-->传给远端的WCF服务 Get.POST.PUT.DELETE,客户端以流的方式调用 ...

  6. 无法通过windows installer服务安装此安装程序包。您必须安装带有更新版本windows Installer服务的Windows

    无法通过windows installer服务安装此安装程序包.您必须安装带有更新版本windows installer服务的Windows 出现这个问题不让安装程序,可以到微软网站更新Windows ...

  7. cordova百度导航插件使用

    org.ssgroup.sope.cordova.baiduNavi 插件已经开源至 https://github.com/shenshouer/org.ssgroup.sope.cordova.ba ...

  8. 基于pydash临控linux服务器

    pydash项目地址:https://github.com/k3oni/pydash 一.安装过程 1.安装pip dnf install git python-pip -ypip install v ...

  9. C#字符串操作大全

    ===============================字符串基本操作================================ 一.C#中字符串的建立过程 例如定义变量 strT=&qu ...

  10. SSO单点登录系列3:cas-server端配置认证方式实践(数据源+自定义java类认证)

    落雨 cas 单点登录 本篇将讲解cas-server端的认证方式 1.最简单的认证,用户名和密码一致就登录成功 2.配置Oracle的jdbc数据源,通过spring动态查询数据库 3.配置orac ...