#include <stdio.h>
int n, y, m, u[99999], v[99999], w[99999], d[9999];
/* xj - xi <= ww */
void inequality(int i, int j, int ww) {
u[y] = i;
v[y] = j;
w[y] = ww;
++y;
}
int main() {
scanf("%d%d", &n, &m);
for (int l, r, k, value; m--; ) {
scanf("%d%d%d%d", &l, &r, &k, &value);
++r;
if (value) {
inequality(r, l, k - r - 1);
} else {
inequality(l, r, r - k);
}
}
for (int i = 0; i <= n; ++i) {
if (i)
inequality(i - 1, i, 1);
inequality(n + 1, i, i);
d[i] = 1e9;
}
for (int j = 0; j <= n; ++j)
for (int i = 0; i < y; ++i) {
if (d[u[i]] + w[i] < d[v[i]]) {
d[v[i]] = d[u[i]] + w[i];
}
}
for (int i = 0; i < y; ++i) {
if (d[u[i]] + w[i] < d[v[i]]) {
puts("-1");
return 0;
}
}
for (int i = 1; i <= n; ++i)
printf("%d ", d[i] - d[i - 1]);
return 0;
}
Compilation message (stderr)
restore.c: In function 'main':
restore.c:14:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
restore.c:17:17: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d%d%d%d", &l, &r, &k, &value);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |