摘要: 两个关系好的牛之间不能超过一定的距离,两个关系不好的牛之间的距离不能少一定的距离。如果存在负还输出-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; 阅读全文
posted @ 2013-04-24 22:00 好小孩 阅读(143) 评论(0) 推荐(0)
摘要: 这个题意 就是利用虫洞时光倒流,题目中给出的虫洞史有向边!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 阅读全文
posted @ 2013-04-24 21:56 好小孩 阅读(147) 评论(0) 推荐(0)
摘要: 求任意两点间的最短距离 若不连通 输出-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... 阅读全文
posted @ 2013-04-24 21:53 好小孩 阅读(108) 评论(0) 推荐(0)
摘要: 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... 阅读全文
posted @ 2013-04-24 21:50 好小孩 阅读(139) 评论(0) 推荐(0)