이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long llint;
typedef pair <int, int> pi;
const int MAXN = 5005;
int n, m;
int dist[MAXN];
vector <pi> v[MAXN];
bool relax () {
bool ok = 0;
for (int i = 0; i <= n + 1; i++) {
for (auto pp : v[i]) {
int sus = pp.first, w = pp.second;
if (dist[sus] > dist[i] + w) {
dist[sus] = dist[i] + w;
ok = 1;
}
}
}
return ok;
}
void bellman_ford () {
dist[n + 1] = 0;
for (int i = 0; i <= n; i++) dist[i] = 1e9;
for (int i = 0; i < n + 1; i++) {
relax();
}
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
v[i - 1].push_back({i, 1});
v[i].push_back({i - 1, 0});
}
for (int i = 0; i < m; i++) {
int lef, rig, k, val;
cin >> lef >> rig >> k >> val;
lef++; rig++;
if (val == 0) {
v[lef - 1].push_back({rig, rig - lef + 1 - k});
} else {
v[rig].push_back({lef - 1, k-1 - (rig - lef + 1)});
}
}
for (int i = 0; i <= n; i++) {
v[n + 1].push_back({i, 0});
}
bellman_ford();
if (relax()) {
cout << -1;
return 0;
}
for (int i = 1; i <= n; i++) {
cout << dist[i] - dist[i - 1] << " ";
}
return 0;
}
# | 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... |