이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*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;
}
}
# | 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... |