hdu1535——Invitation Cards
Invitation Cards
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2173 Accepted Submission(s): 1056
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.
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.
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
46
210
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的更多相关文章
- HDU1535——Invitation Cards(最短路径:SPAF算法+dijkstra算法)
Invitation Cards DescriptionIn the age of television, not many people attend theater performances. A ...
- hdu1535 Invitation Cards 最短路
有一张图,若干人要从不同的点到同一个中间点,再返回,求总费用最小 中间点到各个点最小费用是普通的最短路 各个点到中间点最小费用其实就是将所有路径反向建边之后中间点到各个点的最小费用,同样用最短路就可以 ...
- 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 / ...
- HDU 1535 Invitation Cards(最短路 spfa)
题目链接: 传送门 Invitation Cards Time Limit: 5000MS Memory Limit: 32768 K Description In the age of te ...
- POJ 1511 Invitation Cards (spfa的邻接表)
Invitation Cards Time Limit : 16000/8000ms (Java/Other) Memory Limit : 524288/262144K (Java/Other) ...
- POJ 1511 Invitation Cards (最短路spfa)
Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...
- Poj 1511 Invitation Cards(spfa)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 24460 Accepted: 8091 De ...
- Invitation Cards(邻接表+逆向建图+SPFA)
Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 17538 Accepted: 5721 Description In ...
- [POJ] 1511 Invitation Cards
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 18198 Accepted: 596 ...
随机推荐
- schema get_ddl
select dbms_metadata.get_ddl('INDEX','INDEX_CC_TAXID','CACS9DBSIT1') from dual; select dbms_metadata ...
- [Luogu1429]平面最近点对(加强版)
题目大意: 平面最近点对. 思路: 分治. 首先将所有点排序 每次把当前区间分为两半,递归求解两个区间内部的情况,然后枚举区间两边的点. #include<cmath> #include& ...
- 2.5多线程(Java学习笔记)生产者消费者模式
一.什么是生产者消费者模式 生产者生产数据存放在缓冲区,消费者从缓冲区拿出数据处理. 可能大家会问这样有何好处? 1.解耦 由于有了缓冲区,生产者和消费者之间不直接依赖,耦合度降低,便于程序拓展和维护 ...
- !!!!Linux系统开发 系列 4 进程资源 环境 fork()子进程 wait() waitpid()僵尸 孤儿进程
http://990487026.blog.51cto.com/10133282/1834893
- 【SVN】删除SVN上的历史资源路径和SVN上的历史用户信息
1.删除svn上历史资源路径 window--show view--other--svn资源库 可以右键选择删除 . ----------------------------------------- ...
- java内存溢出分析工具:jmap使用实战
在一次解决系统tomcat老是内存撑到头,然后崩溃的问题时,使用到了jmap. 1 使用命令 在环境是linux+jdk1.5以上,这个工具是自带的,路径在JDK_HOME/bin/下 jmap -h ...
- [转载]How to Install Google Chrome 39 in CentOS/RHEL 6 and Fedora 19/18
FROM: http://tecadmin.net/install-google-chrome-in-centos-rhel-and-fedora/ Google Chrome is a freewa ...
- How is javascript asynchronous AND single threaded?
原文: https://www.sohamkamani.com/blog/2016/03/14/wrapping-your-head-around-async-programming/ ------- ...
- 2017.7.27 logback配置文件
参考来自: Java深入 - logback的配置和使用 1 模块组成 logback分成三个模块:logback-core,logback- classic和logback-access. logb ...
- 转: Java 应用一般架构
http://mp.weixin.qq.com/s?__biz=MzAwMzI3Njc1MA==&mid=2650192186&idx=1&sn=bd08fd3a89f9089 ...