Graph Theory Homework

Problem L. Graph Theory Homework

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

Problem Description

There is a complete graph containing n vertices, the weight of the i-th vertex is wi.
The length of edge between vertex i and j (i≠j) is ⌊|wi−wj|−−−−−−−√⌋.
Calculate the length of the shortest path from 1 to n.

Input

The first line of the input contains an integer T (1≤T≤10) denoting the number of test cases.
Each test case starts with an integer n (1≤n≤105) denoting the number of vertices in the graph.
The second line contains n integers, the i-th integer denotes wi (1≤wi≤105).

Output

For each test case, print an integer denoting the length of the shortest path from 1 to n.

Sample Input

1

3

1 3 5

Sample Output

2


题解:两点之间直线最短

#include <bits/stdc++.h>

using namespace std;
int a[1000005];

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		if(a[0] > a[n-1]){
			int m = a[0];
			a[0] = a[n-1];
			a[n-1] = m;
		}
		printf("%d\n",(int)sqrt(a[n-1] - a[0]));
	} 

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
GrTheory - Graph Theory Toolbox. 内含40个图论问题的matlab代码,包括最短径问题等。对数学建模,2012美赛ICM的帮助尤其大。欢迎下载。 Functions: grBase - find all bases of digraph; grCoBase - find all contrabases of digraph; grCoCycleBasis - find all independent cut-sets for a connected graph; grColEdge - solve the color problem for graph edges; grColVer - solve the color problem for graph vertexes; grComp - find all components of graph; grCycleBasis - find all independent cycles for a connected graph; grDecOrd - solve the problem about decomposition of the digraph to the sections with mutually accessed vertexes (strongly connected components); grDistances - find the distances between any vertexes of graph; grEccentricity - find the (weighted) eccentricity of all vertexes, radius, diameter, center vertexes and the periphery vertexes; grIsEulerian - find the Eulerian cycle of graph; grIsomorph - solve the problem about isomorphism for two graphs; grMaxComSu - solve the maximal complete sugraph problem for the graph; grMaxFlows - solve the maximal flow problem for the digraph; grMaxMatch - solve the maximal matching problem for the graph; grMaxStabSet - solve the maximal stable set problem for the graph; grMinAbsEdgeSet - solve the minimal absorbant set problem for the graph edges; grMinAbsVerSet - solve the minimal absorbant set problem for the graph vertexes; grMinCutSet - solve the minimal cut-set problem for the digraph; grMinEdgeCover - solve the minimal edge cover problem for the graph; grMinSpanTree - solve the minimal spanning tree problem for the graph; grMinVerCover - solve the minimal vertex cover problem for the graph; grPERT - solve the project evaluation research task; grPlot - draw the plot of the graph (digraph); grShortPath - solve the shortest path problem for the digraph; grShortVerPath - for digraph with weighted vertexes solve the problem about the path with minimal weight of verticies; grTranClos - built the transitive closure for the digraph; grTravSale - solve
Graph Theory Authors: Adrian Bondy, U.S.R Murty Publisher: Springer; 3rd Corrected Printing edition (Aug 14 2008) ISBN-10: 1846289696 ISBN-13: 978-1846289699 = Product Description = The primary aim of this book is to present a coherent introduction to graph theory, suitable as a textbook for advanced undergraduate and beginning graduate students in mathematics and computer science. It provides a systematic treatment of the theory of graphs without sacrificing its intuitive and aesthetic appeal. Commonly used proof techniques are described and illustrated. The book also serves as an introduction to research in graph theory. = Table of Contents = Graphs - Subgraphs - Connected Graphs - Trees - Separable and Nonseparable Graphs - Tree-Search Algorithms - Flows in Networks - Complexity of Algorithms - Connectivity - Planar Graphs - The Four-Colour Problem - Stable Sets and Cliques - The Probabilistic Method - Vertex Colourings - Colourings of Maps - Matchings - Edge Colourings - Hamilton Cycles - Coverings and Packings in Directed Graphs - Electrical Networks - Integer Flows and Coverings - Unsolved Problems - References - Glossary - Index = Reviews = For more than three decades, the authors' Graph Theory with Applications (1976) has served as perhaps the classic introduction to graph theory. With happy shock, the reader learns that Bondy and Murty have updated the book, doubling its size. Three decades would count as a long time in the life of any active scientific pursuit, but the original year of publication saw the solution to the four-color conjecture that catalyzed a vast revitalization of graph theory. Graph theory, moreover, now has intimate interactions with computer science, practical and theoretical: three decades ago, computer networks barely existed and the founding papers of complexity theory had just appeared. Connections between graph theory and probability have also undergone a revolution. In short, the passage of time has transformed this subject in these and other ways, and the authors have transformed their book accordingly. They do, by choice, largely omit the theory of graph minors (developed by Paul Seymour and Neil Robertson and followers), which certainly now deserves a monographic treatment of its own. Summing up: Recommended. Lower-division undergraduate through professional collections. CHOICE This book is a follow-on to the authors' 1976 text, Graphs with Applications. What began as a revision has evolved into a modern, first-class, graduate-level textbook reflecting changes in the discipline over the past thirty years... This text hits the mark by appearing in Springer’s Graduate Texts in Mathematics series, as it is a very rigorous treatment, compactly presented, with an assumption of a very complete undergraduate preparation in all of the standard topics. While the book could ably serve as a reference for many of the most important topics in graph theory, it fulfills the promise of being an effective textbook. The plentiful exercises in each subsection are divided into two groups, with the second group deemed "more challenging". Any exercises necessary for a complete understanding of the text have also been marked as such. There is plenty here to keep a graduate student busy, and any student would learn much in tackling a selection of the exercises... Not only is the content of this book exceptional, so too is its production. The high quality of its manufacture, the crisp and detailed illustrations, and the uncluttered design complement the attention to the typography and layout. Even in simple black and white with line art, it is a beautiful book. SIAM Book Reviews "A text which is designed to be usable both for a basic graph theory course … but also to be usable as an introduction to research in graph theory, by including more advanced topics in each chapter. There are a large number of exercises in the book … . The text contains drawings of many standard interesting graphs, which are listed at the end." (David B. Penman, Zentralblatt MATH, Vol. 1134 (12), 2008) MathSciNet Reviews "The present volume is intended to serve as a text for "advanced undergraduate and beginning graduate students in mathematics and computer science" (p. viii). It is well suited for this purpose. The writing is fully accessible to the stated groups of students, and indeed is not merely readable but is engaging… Even a complete listing of the chapters does not fully convey the breadth of this book… For researchers in graph theory, this book offers features which parallel the first Bondy and Murty book: it provides well-chosen terminology and notation, a multitude of especially interesting graphs, and a substantial unsolved problems section…One-hundred unsolved problems are listed in Appendix A, a treasure trove of problems worthy of study… (In short) this rewrite of a classic in graph theory stands a good chance of becoming a classic itself." "The present volume is intended to serve as a text for ‘advanced undergraduate and beginning graduate students in mathematics and computer science’ … . The writing is fully accessible to the stated groups of students, and indeed is not merely readable but is engaging. The book has many exercise sets, each containing problems … ." (Arthur M. Hobbs, Mathematical Reviews, Issue 2009 C) "A couple of fantastic features: Proof techniques: I love these nutshelled essences highlighted in bordered frames. They look like pictures on the wall and grab the view of the reader. Exercises: Their style, depth and logic remind me of Lovász’ classical exercise book. Also the fact that the name of the author is bracketed after the exercise…Figures: Extremely precise and high-tech…The book contains very recent results and ideas. It is clearly an up-to-date collection of fundamental results of graph theory…All-in-all, it is a marvelous book." (János Barát, Acta Scientiarum Mathematicarum, Vol. 75, 2009)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值