博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj1511 Invitation Cards (前向星?)
阅读量:5256 次
发布时间:2019-06-14

本文共 3955 字,大约阅读时间需要 13 分钟。

Invitation Cards
Time Limit: 8000MS   Memory Limit: 262144K
Total Submissions: 20249   Accepted: 6618

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

22 21 2 132 1 334 61 2 102 1 601 3 203 4 102 4 54 1 50

Sample Output

46210

题意:求点1到所有点最短距离之和以及其余点到点1的最短距离(有向边)之和的总和最小值

思路:最短路径,用spfa即可,然后果断TLE了……

于是学习了一下所谓的前向星,好在之前也有看过,所以理解起来也没有很大的麻烦。就好像是建几条链,有关系的连

#include 
#include
#include
#include
#define INF 1000000010using namespace std;int vis[1000010],head1[1000010],head2[1000010];long long dis[1000010];struct edge{ int u,v,next; long long w;}e[1000010],ee[1000010];long long compute(int n,int m){ queue
que; long long ans=0; for(int i=1;i<=n;i++){ dis[i]=INF; } memset(vis,0,sizeof(vis)); dis[1]=0; vis[1]=1; que.push(1); while(!que.empty()){ int d=que.front(); que.pop(); vis[d]=0; for(int i=head1[d];i;i=e[i].next){ if(dis[e[i].v]>dis[d]+e[i].w){ dis[e[i].v]=dis[d]+e[i].w; if(!vis[e[i].v]){ que.push(e[i].v); vis[e[i].v]=1; } } } } for(int i=2;i<=n;i++){ if(dis[i]
dis[d]+ee[i].w){ dis[ee[i].u]=dis[d]+ee[i].w; if(!vis[ee[i].u]){ que.push(ee[i].u); vis[ee[i].u]=1; } } } } for(int i=2;i<=n;i++){ if(dis[i]
在一起,免去了判断是否相连这块(我是这么理解的,不对之处欢迎指正),于是果断ac了。

转载于:https://www.cnblogs.com/Scale-the-heights/p/4322341.html

你可能感兴趣的文章
IOC容器
查看>>
Windows 2003全面优化
查看>>
URAL 1002 Phone Numbers(KMP+最短路orDP)
查看>>
web_day4_css_宽度
查看>>
electron入门心得
查看>>
格而知之2:UIView的autoresizingMask属性探究
查看>>
我的Hook学习笔记
查看>>
js中的try/catch
查看>>
寄Android开发Gradle你需要知道的知识
查看>>
简述spring中常有的几种advice?
查看>>
给你的网站404页面加上“宝贝寻亲”公益页面
查看>>
整理推荐的CSS属性书写顺序
查看>>
ServerSocket和Socket通信
查看>>
css & input type & search icon
查看>>
源代码的下载和编译读后感
查看>>
Kafka学习笔记
查看>>
Octotree Chrome安装与使用方法
查看>>
Windows 环境下基于 Redis 的 Celery 任务调度模块的实现
查看>>
趣谈Java变量的可见性问题
查看>>
C# 强制关闭当前程序进程(完全Kill掉不留痕迹)
查看>>