#include<bits/stdc++.h>
using namespace std;
typedef long long llint;
typedef pair <int, int> pi;
const int MAXN = 5005;
const int MAXM = 10005;
int n, m;
int from[MAXM], to[MAXM], w[MAXM];
int dist[MAXN];
vector <pi> v[MAXN];
bool relax () {
bool ok = 0;
for (int i = 0; i < m; i++) {
if (dist[to[i]] > dist[from[i]] + w[i]) {
dist[to[i]] = dist[from[i]] + w[i];
ok = 1;
}
}
for (int i = 1; i <= n; i++) {
if (dist[i] < dist[i - 1]) {
dist[i] = dist[i - 1];
ok = 1;
}
if (dist[i] > dist[i - 1] + 1) {
dist[i] = dist[i - 1] + 1;
ok = 1;
}
}
return ok;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int lef, rig, k, val;
cin >> lef >> rig >> k >> val;
lef++; rig++;
if (val == 0) {
from[i] = lef - 1; to[i] = rig; w[i] = rig - lef + 1 - k;
} else {
from[i] = rig; to[i] = lef - 1; w[i] = k-1 - (rig - lef + 1);
}
}
for (int i = 0; i < n + 1; i++) {
if (!relax()) break;
}
if (relax()) {
cout << -1;
return 0;
}
for (int i = 1; i <= n; i++) {
cout << dist[i] - dist[i - 1] << " ";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
110 ms |
620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
110 ms |
620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |