题目大意:
有n个小孩,m个约束条件,每个约束条件为A B C表示A认为B不应该比自己多超过C个糖。问你1号小孩和n号小孩最多相差多少个糖
解题思路:
差分约束
代码:
#include <cstdio>
#include <cstring>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 30000 + 5;
const int maxm = 150000 + 5;
typedef struct node{
int to, w;
int next;
}Edge;
int tol;
Edge edge[maxm];
int s[maxm], head[maxm], dis[maxn], vis[maxn];
void add(int a, int b, int c){
edge[tol].to = b;
edge[tol].w = c;
edge[tol].next = head[a];
head[a] = tol++;
}
int spfa(int n){
int p, v, top = 0;
for(int i = 0; i <= n; ++i){
dis[i] = INF;
vis[i] = 0;
}
dis[1] = 0; vis[1] = 1; s[top++] = 1;
while(top){
p = s[--top]; vis[p] = 0;
for(int