随笔分类 - 最短路
摘要:迪杰斯特拉 + 优先队列 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 9 #define LL __int64 10 11 const LL INF = 2000000000; 12 13 using namespace std; 14 15 LL dis[300100]; 16 17 int head[300100]; 18 19 struct E 20 { 21 int u,v,w,next; 22 }edge[100...
阅读全文
摘要:求最长路中的最短路……略显绕嘴 最长路定义为该条路上青蛙调的最远的那一步。应该算是水题,感觉思路比较新颖,主要是权值的定义。 两种算法 很显然 后一种从效率上明显优于前一种 Floyd 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 9 using namespace std;10 11 float path[210][210];12 13 float Max(float a,float b)14 {15 return a > b ? a : b;16 ...
阅读全文
摘要:SPFA 第二次用到 超级源点 这个概念,依稀记得第一次用还是小时候...... 逆向建图,添加超级源的时候是顺向建立。 0号点为超级源。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 9 using namespace std; 10 11 struct N 12 { 13 int g,p,v; 14 N *next; 15 }*head[110]; 16 17 N *creat() 18 { 19 ...
阅读全文
摘要:两个关系好的牛之间不能超过一定的距离,两个关系不好的牛之间的距离不能少一定的距离。如果存在负还输出-1,牛1和牛N不连通 输出-2,否则输出他们的之间距离。 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 5 struct N 6 { 7 int u,v,w; 8 } edge[20010]; 9 10 int dis[1010];11 int INF = (1<<29);12 13 int bellman_ford(int n,int e)14 {15 int flag;
阅读全文
摘要:这个题意 就是利用虫洞时光倒流,题目中给出的虫洞史有向边!SPFA水过~~这个跑了204ms 第一次写 应该是邻接矩阵的缘故……sad 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 5 using namespace std; 6 7 const int INF = (1<<20); 8 9 10 int dis[100000]; 11 12 struct N 13 { 14 int u,v,w; 15 struct N *next; 16 }*head[510]; 17
阅读全文
摘要:求任意两点间的最短距离 若不连通 输出-1 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 5 using namespace std; 6 7 const int Max = 100000001; 8 9 struct N 10 { 11 int v,w; 12 N *next; 13 }*head[210]; 14 15 void init(int n) 16 { 17 for(int i = 0;i < n; i++) 18 { 19 hea...
阅读全文
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 5 using namespace std; 6 7 const int Max = 100000001; 8 9 struct N 10 { 11 int v,w; 12 N *next; 13 }*head[110]; 14 15 void init(int n) 16 { 17 for(int i = 1;i <= n; i++) 18 { 19 head[i] = (struct N *)m...
阅读全文
浙公网安备 33010602011771号