This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int k_N = 5000 + 3;
const int k_M = 10000 + 3;
const int k_Inf = 1e9 + 3;
int n, m;
vector<array<int, 3>> edges;
int prefix[k_N];
bool bellman_ford(){
prefix[0] = 0;
for(int i = 1; i <= n; ++i)
prefix[i] = k_Inf;
for(int i = 0; i < n; ++i){
for(auto &edge: edges){
int new_prefix = prefix[edge[0]] + edge[2];
prefix[edge[1]] = min(new_prefix, prefix[edge[1]]);
}
}
for(auto &edge: edges){
int new_prefix = prefix[edge[0]] + edge[2];
if(new_prefix < prefix[edge[1]])
return false;
}
return true;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; ++i){
edges.push_back({i - 1, i, 1});
edges.push_back({i, i - 1, 0});
}
for(int i = 0; i < m; ++i){
int l, r, k, value;
cin >> l >> r >> k >> value;
l++, r++;
if(value == 0)
edges.push_back({l - 1, r, (r - l + 1) - k});
else if(value == 1)
edges.push_back({r, l - 1, -((r - l + 1) - k + 1)});
}
if(!bellman_ford()){
cout << "-1\n";
return 0;
}
for(int i = n; i >= 1; --i)
prefix[i] -= prefix[i - 1];
for(int i = 1; i <= n; ++i)
cout << prefix[i] << " ";
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... |