이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> graph(n + 1);
for (int v = 0; v < n; ++v) {
graph[v + 1].emplace_back(v, 0);
graph[v].emplace_back(v + 1, 1);
}
while (m--) {
int l, r, k, v;
cin >> l >> r >> k >> v;
if (v) {
graph[r + 1].emplace_back(l, k - r + l - 2);
} else {
graph[l].emplace_back(r + 1, r - l + 1 - k);
}
}
const auto inf = numeric_limits<int>::max() >> 1;
vector<int> distance(n + 1, inf);
distance[0] = 0;
bool exists = true;
for (int phase = 0; phase <= n; ++phase) {
exists = true;
for (int u = 0; u < n; ++u) {
if (distance[u] < inf) {
for (const auto& [v, w] : graph[u]) {
if (distance[v] > distance[u] + w) {
exists = false;
distance[v] = distance[u] + w;
}
}
}
}
}
if (!exists) {
cout << -1 << '\n';
} else {
for (int v = 0; v < n; ++v) {
cout << distance[v + 1] - distance[v] << ' ';
}
cout << '\n';
}
}
# | 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... |