本文共 1730 字,大约阅读时间需要 5 分钟。
设sum(u)为在结点u上的全部操作叠加(操作顺序无影响)
则原边w(a,b)变为w(a,b)+sum(a)-sum(b)
二分答案x,则w(a,b)+sum(a)-sum(b)>=x,即sum(b)-sum(a)<=w(a,b)-x
差分约束系统
构图用SPFA判断是否有解。
//#pragma comment(linker, "/STACK:1024000000,1024000000")#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair pii;#define pb(a) push(a)#define INF 0x1f1f1f1f#define lson idx<<1,l,mid#define rson idx<<1|1,mid+1,r#define PI 3.1415926535898template T min(const T& a,const T& b,const T& c) { return min(min(a,b),min(a,c));}template T max(const T& a,const T& b,const T& c) { return max(max(a,b),max(a,c));}void debug() {#ifdef ONLINE_JUDGE#else freopen("d:\\in1.txt","r",stdin); freopen("d:\\out1.txt","w",stdout);#endif}int getch() { int ch; while((ch=getchar())!=EOF) { if(ch!=' '&&ch!='\n')return ch; } return EOF;}struct Edge{ int from,to; int dist;};const int maxn=505;vector g[maxn];vector edge;int d[maxn];int inq[maxn];int inq_cnt[maxn];int n,m;int limit;void init(){ limit=(int)sqrt(n)+1; for(int i=0;i<=n;i++)g[i].clear(); edge.clear();}void add(int u,int v,int w){ Edge e=(Edge){u,v,w}; edge.push_back(e); g[u].push_back(edge.size()-1);}bool negativeCycle(int s){ queue q; memset(inq,0,sizeof(inq)); memset(inq_cnt,0,sizeof(inq_cnt)); for(int i=0;i<=n;i++) { d[i]=0; inq[i]=1; q.push(i); } while(!q.empty()) { int u=q.front();q.pop(); inq[u]=0; for(int i=0;i limit)return true; } } } } return false;}bool check(int x){ for(int i=0;i
转载于:https://www.cnblogs.com/BMan/p/3632945.html