# HDU - 6252 Subway Chasing （差分约束）

## 题目链接

=号可以转换成 >= && <=

<X可以转换成 <=X-1

>X可以转换成 >=X+1

#include <iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
#include<stack>
#include<string>

const int mod = 1e9 + 7;
const int maxn = 1e4 + 5;
const int inf = 2e9;
const long long onf = 1e18;
#define me(a, b) memset(a,b,sizeof(a))
#define lowbit(x) x&(-x)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI 3.14159265358979323846
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int n, m, x;
int dis[maxn];
struct node {
int v, next, val;
} maps[maxn << 1];

void add_edge(int u, int v, int val) {
}

void init() {
for (int i = 0; i <= n; i++)
tot = 0;
}

bool SPFA(int st) {
int cnt[maxn], vis[maxn];
for (int i = 1; i <= n; i++)
vis[i] = 0, dis[i] = inf, cnt[i] = 0;
queue<int> q;
vis[st] = 1, cnt[st] = 1, dis[st] = 0;
q.push(st);
while (!q.empty()) {
int u = q.front();
q.pop(), vis[u] = 0;
for (int i = head[u]; i != -1; i = maps[i].next) {
int v = maps[i].v, val = maps[i].val;
if (dis[v] > dis[u] + val) {
dis[v] = dis[u] + val;
if (!vis[v]) {
vis[v] = 1, cnt[v]++;
q.push(v);
if (cnt[v] >= n)///判断是否有负环
return false;
}
}
}
}
return true;
}

void work() {
scanf("%d%d%d", &n, &m, &x);
init();
for (int i = 1; i <= m; i++) {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
if (a == b && c == d) {
} else if ((b == c && c == d) || (a == b && b == c)) {
} else {
}
}
for (int i = 1; i <= n; i++) {
if (i > 1)
}
if (!SPFA(0))
puts("IMPOSSIBLE");
else {
for (int i = 2; i <= n; i++)
printf("%d ", dis[i] - dis[i - 1]);
printf("\n");
}
}

int main() {
#ifndef ONLINE_JUDGE
//freopen("1.in", "r", stdin);
#endif
int t = 1, Case = 1;
cin >> t;
while (t--) {
printf("Case #%d: ", Case++);
work();
}
return 0;
}

12-14 978

10-23 229

10-23 64

12-10 405

09-18 232

10-17 222

10-11 150

01-13 54

08-06 80

10-09 63

#### HDU - 6252 Subway Chasing （差分约束 spfa最长路）

©️2020 CSDN 皮肤主题: 创作都市 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。