昨天的题太水了,堆优化跑的不爽,今天换了一个题,1000000个点,1000000条边= = 试一试邻接表 写的过程中遇到了一些问题,由于习惯于把数据结构封装在 struct 里,结果 int [1000000] 导致 struct 爆栈,此问题亟待解决.. 实力碾压SPFA 2500 ms,有图为证 #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #d…
POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径) Description In the age of television, not many people attend theater perfor…
Invitation Cards Time Limit : 16000/8000ms (Java/Other)   Memory Limit : 524288/262144K (Java/Other) Total Submission(s) : 7   Accepted Submission(s) : 1 Problem Description In the age of television, not many people attend theater performances. Antiq…
题目链接:http://poj.org/problem?id=1511 就是求从起点到其他点的最短距离加上其他点到起点的最短距离的和 , 注意路是单向的. 因为点和边很多, 所以用dijkstra优先队列的做法. 起点到其他点的最短距离之和就是dij一下 . 要求其他点到起点的最短距离的话就是把原先边的方向反向一下,然后再求起点到其他点的最短距离之和 , 同样dij一下. 代码如下: #include <iostream> #include <cstdio> #include &l…
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 wan…
传送门: http://poj.org/problem?id=1511 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1008 题目大意: 给定p个点,还有他们的边q,(有向图)求从结点1出发到所有结点和所有结点到1的最短路径之和. 其中1 <= P,Q <= 1000000 思路: 和上次 POJ 3268 Silver Cow Party 一样,有向图倒着建立就把从所有结点到1的最短路径改为了从1到所有,那么只需两次d…
题意: 给定一个有向图,求从源点到其他各点的往返最短路径和.且这个图有一个性质:任何一个环都会经过源点. 图中的节点个数范围:0-100w; 分析: 我们先可以利用Dijkstra算法求解从源点到其余各点的最短距离,这样工作就完成了一半了. 那么如何求解从各点到源点的最短路呢? 1. 我们可以循环n-1次,每次计算点i到其余各点的最短路,从中取出i到源点的最短路,这样我们就可以其余各点到源点的最短路. 显然上述方法中存在大量冗余,显然针对题目的取值范围:0~100w,必定会超时的.如果你不信,可…
题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. POJ 3268 //#include <bits/stdc++.h> #include <cstdio> #include <queue> #include <algorithm> #include <cstring> using namespace…
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 24460 Accepted: 8091 Description In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to…
Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 18198   Accepted: 5969 Description In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They wan…
原题: Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 31230   Accepted: 10366 Description In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. The…
题目链接: http://poj.org/problem?id=1511 题目大意: 这道题目比较难理解,我读了好长时间,最后还是在队友的帮助下理解了题意,大意就是,以一为起点,求从一到其他各点的最短回路总和. 解题思路: 解决这个题目有几个容易错的,解决了离ac就不远了^_^. 1:数据范围是1<=边数<=顶点数<=1000000,所以不能用邻接矩阵,要用邻接表,用vector实现时要动态申请内存. 2:求得是起始点到其他点的最短回路和,我们可以建两个邻接表(一个正向,一个负向邻接表)…
Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J 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 a…
题意:学生从A站到B站花费C元,将学生每天从‘1’号站送往其它所有站,再从所有站接回到‘1’号站,问着个过程最小花费是多少. 思路:因为数据很大所以要用SPFA,因为不仅要从1点连接各个点还要从各个点返回一点,所以需要正邻接表和逆邻接表.然后正反各跑一次SPFA,值得注意的是因为数据很大,要将INF定位0xffffffff. #include<stdio.h> #include<string.h> #include<cstring> #include<string…
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…
Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 27200   Accepted: 9022 Description In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They wan…
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 necessa…
Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 33435   Accepted: 11104 Description In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They wa…
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…
题目链接:http://poj.org/problem?id=1511 题目大意:给你n个点,m条边(1<=n<=m<=1e6),每条边长度不超过1e9.问你从起点到各个点以及从各个点到起点的最小路程总和. 解题思路:这里用了优先队列优化的dijkstra复杂度mlogn,从起点到个点最短路径直接算就好了,算各个点到起点的最短路径,只要把边的方向反一下,再算一次从起点到个点最短路径就好了. Dijkstra: #include<iostream> #include<cs…
题目链接:http://poj.org/problem?id=1511 题意:给出n个点和n条有向边,求所有点到源点1的来回最短路之和(保证每个点都可以往返源点1) 题目比较简单就是边和点的个数有点多所以可以用dijstra+优先队列这样复杂度就可以到v*logn #include <iostream> #include <cstring> #include <string> #include <vector> #include <queue>…
题意: 给定n个点, m条路, 求1到 2 ~n的最短路之和加上2~n到1的最短路之和 分析: 裸最短路, 求其他点到源点的距离只需要把边方向再从源点求一次即可 spfa代码 #include<iostream> #include<vector> #include<algorithm> #include<cstring> #include<cstdio> #include<cmath> #include<cstdlib>…
题意 : 给出 P 个顶点以及 Q 条有向边,求第一个点到其他各点距离之和+其他各点到第一个点的距离之和的最小值 分析 : 不难看出 min( 第一个点到其他各点距离之和+其他各点到第一个点的距离之和 ) = min( 第一个点到其他各点距离之和) + min( 其他各点到第一个点的距离之和 ),前者较为简单,建好图后直接跑一遍最短路即得,关键在于后者怎么方便的求出来.这里利用到了一个逆向思维,如果将所有的有向边反过来,那么就能求出其他点到源点的最短路了,那么只要存储两种边,一个正向边(即题目所…
分析:正向加边,反向加边,然后两遍dij #include<cstdio> #include<cstring> #include<queue> #include<cstdlib> #include<algorithm> #include<vector> #include<cmath> using namespace std; typedef long long LL; ; const int INF=0x3f3f3f3f;…
已知图中从一点到另一点的距离,从1号点到另一点再从这一点返回1号点,求去到所有点的距离之和最小值 *解法:正着反着分别建图,把到每个点的距离加起来 spfa跑完之后dist数组就是从起点到每一点的最短距离 get反着建图这种技能 #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; #define SZ 1000005 #d…
Delay Constrained Maximum Capacity Path Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 544    Accepted Submission(s): 192 Problem Description Consider an undirected graph with N vertices, nu…
做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 -> n - 1 d[i] = dis[0][i] while u = GetNearest(1 .. n - 1, !been[]) been[u] = 1 for_each edge from u d[edge.v] = min(d[edge.v], d[u] + dis[u][edge.v]…
例题: Time Limit: 1 second Memory Limit: 128 MB [问题描述] 在电视时代,没有多少人观看戏剧表演.Malidinesia古董喜剧演员意识到这一事实,他们想宣传剧院,尤其是古色古香的喜剧片.他们已经打印请帖和所有必要的信息和计划.许多学生被雇来分发这些请柬.每个学生志愿者被指定一个确切的公共汽车站,他或她将留在那里一整天,邀请人们参与. 这里的公交系统是非常特殊的:所有的线路都是单向的,连接两个站点.公共汽车离开起始点,到达目的地之后又空车返回起始点.…
2834: 回家的路 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 62  Solved: 38[Submit][Status][Discuss] Description Input Output Sample Input 2 1 1 2 1 1 2 2 Sample Output 5 HINT N<=20000,M<=100000 Source dijkstra+堆优化+分层图 把所有的横向和纵向分开看.跑最短路即可. 注意:N这么大,不能写…
Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty sleep, so she wants to get back as quickly as possible.…