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. EGS5在linux系统下安装过程

    转载自52MC论坛 作者:xinruibj 平台:Fedora 13 内核版本为:2.6.33, g77版本为:3.4.6: 用户名为xinrui,下面出现这个文件夹xinrui时,修改为你自己的用户 ...

  2. java.util.List.subList ,开区间和闭区间

    比如集合中的内容为1,2,3,4,5list.sublist(2,4)就返回一个子集合:它的内容包括从下标为2到下标为4,而且这是左闭右开的就是说是从大于等于2到小于4那子集内容就是3,4(集合的下标 ...

  3. 基于Android的串口聊天室 (基于tiny4412) 一

    一.平台介绍 硬件平台: tiny4412ADK + S700 4GB Flash Android版本:Android-5.0.2 Linux版本: Linux-3.0.86 Bootloader:S ...

  4. What is Mocking?

    Mocking is primarily used in unit testing. An object under test may have dependencies on other (comp ...

  5. 【Mybatis】未封装返回结果的字段自己返回值的问题

    在spring boot中使用mybatis过程中,发现有个实体的时间字段未在mapper方法执行完的封装结果中进行封装,但是却有值返回. 如下展示问题: 实体如下: package com.sxd. ...

  6. .NET Core简介

    内容主要来源 https://docs.asp.net/en/latest/conceptual-overview/dotnetcore.html 什么是.NET Core .NET Core 5 包 ...

  7. C# 下利用ICSharpCode.SharpZipLib.dll实现文件/目录压缩、解压缩

    ICSharpCode.SharpZipLib.dll下载地址 1.压缩某个指定文件夹下日志,将日志压缩到CompressionDirectory文件夹中,并清除原来未压缩日志. #region 压缩 ...

  8. Spark map-side-join 关联优化

    在spark中要进行join操作,如果在shuffle的时候进行join效率较低.如果满足 所需要join的表中有一张表较小,那么可以考虑在map端进行join操作. 转载:http://blog.c ...

  9. 关于ElasticSearch默认窗口结果集参数max_result_window修改

    在Linux服务器中执行如下命令 curl -XPUT http://192.168.46.163:9200/t_order/_settings -d '{ "index" : { ...

  10. eclipse maven项目导入Intellij问题处理

    1.maven打包编译时后台一直输出警告信息 [WARNING] File encoding has not been set, using platform encoding GBK, i.e. b ...