一个差分约束模型,只需判一下有没有负环即可. #include <bits/stdc++.h> #define N 103 #define M 2004 #define setIO(s) freopen(s".in","r",stdin) using namespace std; int edges; int hd[N],to[M],nex[M],val[M],d[N],vis[N]; void add(int u,int v,int c) { nex[
相比dij,spfa优点是可处理含负边不含负圈的最短路问题,缺点是算法复杂度不太好[貌似可以使用两种优化.LLL和SLF] 差分约束就是将一些不等式转化为图中的带权边,然后求解最短路或最长路的方法 洛谷P1645https://www.luogu.org/problemnew/show/P1645 #include<bits/stdc++.h> using namespace std; struct pot{ int to; int next; int len; }edge[]; queue&
Time Limit: 1500MS Memory Limit: 131072K Description During the kindergarten days, flymouse was the monitor of his class. Occasionally the head-teacher brought the kids of flymouse's class a large bag of candies and had flymouse distribute them. All
原题:ZOJ 3668 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3668 典型差分约束题. 将sum[0] ~ sum[n] 作为节点,A<=sum[R]-sum[L-1]<=B可以分别建边: x(L-1)-->xR w = B xR --> x(L-1) w = -A 注意还有 -10000<=sum[i]-sum[i-1]<=10000 (for i in (2,n)),所以相邻点