#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int E = 20020;
int from[E], to[E], cost[E], edges = 0;
int add_edge(int u, int v, int w) {
from[edges] = u;
to[edges] = v;
cost[edges] = w;
return edges++;
}
const int N = 5007;
const int INF = 10001000;
int n, dist[N];
bool ford_bellman() {
dist[0] = 0;
for (int i = 1; i <= n; ++i) {
dist[i] = INF;
}
for (int i = 0; i < n; ++i) {
bool found = false;
for (int e = 0; e < edges; ++e) {
if (dist[from[e]] != INF && dist[from[e]] + cost[e] < dist[to[e]]) {
found = true;
dist[to[e]] = dist[from[e]] + cost[e];
}
}
if (i == n - 1 && found) {
return false;
}
}
return true;
}
int main() {
#ifdef ONPC
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int m;
cin >> n >> m;
while (m--) {
int l, r, k, val;
cin >> l >> r >> k >> val;
++r;
if (val == 0) {
add_edge(l, r, r - l - k);
} else {
add_edge(r, l, -(r - l - k + 1));
}
}
for (int i = 0; i < n; ++i) {
add_edge(i, i + 1, 1);
add_edge(i + 1, i, 0);
}
if (ford_bellman()) {
for (int i = 1; i <= n; ++i) {
cout << (dist[i] != dist[i - 1]) << " "[i == n];
}
cout << '\n';
} else {
cout << "-1\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
748 KB |
Output is correct |
2 |
Correct |
140 ms |
876 KB |
Output is correct |
3 |
Correct |
135 ms |
748 KB |
Output is correct |
4 |
Correct |
142 ms |
876 KB |
Output is correct |
5 |
Correct |
355 ms |
748 KB |
Output is correct |
6 |
Correct |
330 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
748 KB |
Output is correct |
2 |
Correct |
140 ms |
876 KB |
Output is correct |
3 |
Correct |
135 ms |
748 KB |
Output is correct |
4 |
Correct |
142 ms |
876 KB |
Output is correct |
5 |
Correct |
355 ms |
748 KB |
Output is correct |
6 |
Correct |
330 ms |
748 KB |
Output is correct |
7 |
Correct |
146 ms |
748 KB |
Output is correct |
8 |
Correct |
152 ms |
864 KB |
Output is correct |
9 |
Correct |
142 ms |
748 KB |
Output is correct |
10 |
Correct |
135 ms |
748 KB |
Output is correct |
11 |
Correct |
362 ms |
640 KB |
Output is correct |
12 |
Correct |
403 ms |
748 KB |
Output is correct |
13 |
Correct |
144 ms |
800 KB |
Output is correct |
14 |
Correct |
139 ms |
876 KB |
Output is correct |
15 |
Correct |
144 ms |
876 KB |
Output is correct |
16 |
Correct |
151 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
142 ms |
748 KB |
Output is correct |
12 |
Correct |
140 ms |
876 KB |
Output is correct |
13 |
Correct |
135 ms |
748 KB |
Output is correct |
14 |
Correct |
142 ms |
876 KB |
Output is correct |
15 |
Correct |
355 ms |
748 KB |
Output is correct |
16 |
Correct |
330 ms |
748 KB |
Output is correct |
17 |
Correct |
146 ms |
748 KB |
Output is correct |
18 |
Correct |
152 ms |
864 KB |
Output is correct |
19 |
Correct |
142 ms |
748 KB |
Output is correct |
20 |
Correct |
135 ms |
748 KB |
Output is correct |
21 |
Correct |
362 ms |
640 KB |
Output is correct |
22 |
Correct |
403 ms |
748 KB |
Output is correct |
23 |
Correct |
144 ms |
800 KB |
Output is correct |
24 |
Correct |
139 ms |
876 KB |
Output is correct |
25 |
Correct |
144 ms |
876 KB |
Output is correct |
26 |
Correct |
151 ms |
748 KB |
Output is correct |
27 |
Correct |
134 ms |
748 KB |
Output is correct |
28 |
Correct |
135 ms |
748 KB |
Output is correct |
29 |
Correct |
134 ms |
876 KB |
Output is correct |
30 |
Correct |
139 ms |
876 KB |
Output is correct |
31 |
Correct |
132 ms |
748 KB |
Output is correct |
32 |
Correct |
133 ms |
780 KB |
Output is correct |
33 |
Correct |
361 ms |
876 KB |
Output is correct |
34 |
Correct |
361 ms |
876 KB |
Output is correct |
35 |
Correct |
159 ms |
748 KB |
Output is correct |
36 |
Correct |
135 ms |
748 KB |
Output is correct |