博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1511 Invitation Cards(单源最短路,优先队列优化的Dijkstra)
阅读量:5870 次
发布时间:2019-06-19

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

Invitation Cards
Time Limit: 8000MS   Memory Limit: 262144K
Total Submissions: 16178   Accepted: 5262

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

Source

 
 
 
 
做两遍最短路。
 
模板题
 
//============================================================================// Name        : POJ.cpp// Author      : // Version     :// Copyright   : Your copyright notice// Description : Hello World in C++, Ansi-style//============================================================================#include 
#include
#include
#include
#include
#include
using namespace std;/* * 使用优先队列优化Dijkstra算法 * 复杂度O(ElogE) * 注意对vector
E[MAXN]进行初始化后加边 */const int INF=0x3f3f3f3f;const int MAXN=1000010;struct qnode{ int v; int c; qnode(int _v=0,int _c=0):v(_v),c(_c){} bool operator <(const qnode &r)const { return c>r.c; }};struct Edge{ int v,cost; Edge(int _v=0,int _cost=0):v(_v),cost(_cost){}};vector
E[MAXN];bool vis[MAXN];int dist[MAXN];void Dijkstra(int n,int start)//点的编号从1开始{ memset(vis,false,sizeof(vis)); for(int i=1;i<=n;i++)dist[i]=INF; priority_queue
que; while(!que.empty())que.pop(); dist[start]=0; que.push(qnode(start,0)); qnode tmp; while(!que.empty()) { tmp=que.top(); que.pop(); int u=tmp.v; if(vis[u])continue; vis[u]=true; for(int i=0;i
dist[u]+cost) { dist[v]=dist[u]+cost; que.push(qnode(v,dist[v])); } } }}void addedge(int u,int v,int w){ E[u].push_back(Edge(v,w));}int A[MAXN],B[MAXN],C[MAXN];int main(){// freopen("in.txt","r",stdin);// freopen("out.txt","w",stdout); int n,m; int T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); for(int i=0;i

 

 
 

转载地址:http://ljxnx.baihongyu.com/

你可能感兴趣的文章
【Java学习路线图,看你掌握了多少】附全部知识点免费视频课程,名师主讲
查看>>
mysql多表查询
查看>>
angular 实现 echarts 拖动区域进行放大 方法
查看>>
python安装
查看>>
《F4+2—团队项目设计完善&编码测试》
查看>>
OpenCV学习(19) 细化算法(7)
查看>>
哈希表结构
查看>>
[leetcode-144-Binary Tree Preorder Traversal]
查看>>
[leetcode-611-Valid Triangle Number]
查看>>
Linux常用命令:ls命令
查看>>
uva-331-枚举-交换的方案数
查看>>
机器学习PAI快速入门
查看>>
H5网页涂鸦canvas
查看>>
Python基础1—搭建环境
查看>>
(转)android UI进阶之实现listview的下拉加载
查看>>
php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法(转)
查看>>
mysql出现Got error 28 from storage engine错误
查看>>
elasticsearch-head 安装
查看>>
Hyperledger Fabric 1.1 -- Policy 构成
查看>>
leetcode-506-Relative Ranks
查看>>