/*input
4 5
0 1 2 1
0 2 2 0
2 2 1 0
0 1 1 0
1 2 1 0
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> g(n + 1);
while (m--) {
int l, r, k, x;
cin >> l >> r >> k >> x;
++r;
if (x == 0) g[l].emplace_back(r - l - k, r);
else g[r].emplace_back(k - r + l, l);
}
for (int i = 0; i < n; ++i) g[i].emplace_back(1, i + 1);
for (int i = 0; i < n; ++i) g[i + 1].emplace_back(0, i);
vector<int> min_dist(n + 1, n + 2);
min_dist[0] = 0;
bool unfinished = true;
for (int i = 0; unfinished; ++i) {
if (i > n + 1) break;
unfinished = false;
for (int u = 0; u <= n; ++u) {
for (auto p : g[u]) {
if (min_dist[u] + p.first < min_dist[p.second]) {
min_dist[p.second] = min_dist[u] + p.first;
unfinished = true;
}
}
}
}
if (unfinished) {
cout << -1 << endl;
} else {
for (int i = 0; i < n; ++i) {
cout << min_dist[i + 1] - min_dist[i] << ' ';
}
cout << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
884 KB |
Output is correct |
2 |
Correct |
6 ms |
832 KB |
Output is correct |
3 |
Correct |
6 ms |
844 KB |
Output is correct |
4 |
Incorrect |
7 ms |
844 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
884 KB |
Output is correct |
2 |
Correct |
6 ms |
832 KB |
Output is correct |
3 |
Correct |
6 ms |
844 KB |
Output is correct |
4 |
Incorrect |
7 ms |
844 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |