POJ - 3037-Skiing(邻接表+Dijkstra)】的更多相关文章

Bessie and the rest of Farmer John's cows are taking a trip this winter to go skiing. One day Bessie finds herself at the top left corner of an R (1 <= R <= 100) by C (1 <= C <= 100) grid of elevations E (-25 <= E <= 25). In order to joi…
昨天的题太水了,堆优化跑的不爽,今天换了一个题,1000000个点,1000000条边= = 试一试邻接表 写的过程中遇到了一些问题,由于习惯于把数据结构封装在 struct 里,结果 int [1000000] 导致 struct 爆栈,此问题亟待解决.. 实力碾压SPFA 2500 ms,有图为证 #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #d…
题目链接:http://poj.org/problem?id=1511 思路:题目意思很简单就是要求源点到各点的最短路之和,然后再求各点到源点的最短路之和,其实就是建两个图就ok了,其中一个建反图.1000000个点和1000000条边,一开始用SPFA+vector怎么都是TLE,然后换成邻接表就过了=.=. #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #inc…
题目大意: 一共有N (1 ≤ N ≤ 1,000)个电线杆,有P P (1 ≤ P ≤ 10,000)对电线杆是可以连接的, 用几条线连接在一起的电线杆之间都可相互通信,现在想要使得电线杆1和电线杆N能相互通信, 并且电线公司提出KK (0 ≤ K < N)条电线是可以免费使用的, 当使用电线的数量超过K条,超出的电线要收费, 收的总费用为去掉免费使用的K条电线之后最长的那条电线的长度. 问最少费用是多少 Input * Line 1: Three space-separated intege…
题意:给出m条边 , n个顶点,u [ i ]到v [ i ] 的距离w [ i ],求除了最短路的那条最短的边的长度. 思路:之前有做过相似的题,使用迪杰斯特拉算法求单源最短路径,并且记录路径,枚举每段路径不存在的时候的最短路径,求最小值.不过这道题数据太大,邻接矩阵存不下,听说用单源最短路径会超时,所以用邻接表存,用SPFA算法求1号点到其他所有点的最短路径,再用一次SPFA求出n号点到所有顶点的距离,最后枚举每一条边,求大于最短路径的最小值(可能表述不清,代码最后一个for循环,容易理解,…
Skiing Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4668   Accepted: 1242   Special Judge Description Bessie and the rest of Farmer John's cows are taking a trip this winter to go skiing. One day Bessie finds herself at the top left c…
题目链接: https://cn.vjudge.net/problem/POJ-3037 Bessie and the rest of Farmer John's cows are taking a trip this winter to go skiing. One day Bessie finds herself at the top left corner of an R (1 <= R <= 100) by C (1 <= C <= 100) grid of elevati…
Skiing Bessie and the rest of Farmer John's cows are taking a trip this winter to go skiing. One day Bessie finds herself at the top left corner of an R (1 <= R <= 100) by C (1 <= C <= 100) grid of elevations E (-25 <= E <= 25). In order…
题目链接:http://poj.org/problem?id=3268 题意: 有编号为1-N的牛,它们之间存在一些单向的路径.给定一头牛的编号,其他牛要去拜访它并且拜访完之后要返回自己原来的位置,求这些牛中所花的最长的来回时间是多少. 思路: 很骚的写法,这里用了两个数组标记,head,next,他每次找到下一个结点后,head就赋给next了,然后head又是一条新的边,这样,我在遍历这个链表的时候,就能从后往前遍历了,我推了一个小时. 然后这里的if语句也很重要,要先松弛,再看前一个结点有…
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…