#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <functional>
#include <complex>
#include <random>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
const ll maxn = 1e4 + 1, maxm = 1e4 + 1;
const ll mod = 1e9 + 7, cmod = 998244353, inf = 1e9, block = 5000, p2 = 31, bit = 30;
const ld eps = 1e-9;
int n, m;
int dp[maxn];
vector<pair<pair<int, int>, int>> edge;
int bellman_ford(){
for (int i = 0; i <= n; ++i){
dp[i] = inf;
}
int last = -1;
dp[0] = 0;
for (int i = 1; i <= n + 1; ++i){
last = -1;
for (auto it : edge){
int x = it.f.f, y = it.f.s, z = it.s;
if (dp[x] != inf && dp[y] > dp[x] + z){
dp[y] = dp[x] + z;
last = i;
}
}
}
//cout << "ok\n";
return (last == n + 1);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; ++i){
int l, r, k, val;
cin >> l >> r >> k >> val;
r++;
k = r - l - k;
if (val == 1){
edge.pb(mp(mp(r, l), -k));
// cout << r << " " << l << " " << -k << '\n';
}
else{
edge.pb(mp(mp(l, r), k));
// cout << l << " " << r << " " << k << '\n';
}
}
for (int i = 1; i <= n; ++i){
edge.pb(mp(mp(i, i - 1), 0));
// cout << i << " " << i - 1 << " " << 0 << '\n';
edge.pb(mp(mp(i - 1, i), 1));
// cout << i - 1 << " " << i << " " << 1 << '\n';
}
if (bellman_ford()){
cout << -1;
exit(0);
}
for (int i = 1; i <= n; ++i){
cout << dp[i] - dp[i - 1] << " ";
}
}
/*
pref[r] - pref[l] >= k
pref[l] - pref[r] <= -k
pref[r] - pref[l] <= k;
p[i - 1] - p[i] <= 0
p[i] - p[i - 1] <= 1
ajj, ajj, ajj, ajj, aj, aj, aj, aj, aj, aj, ak, ak, ak, ak, ak, ai, ai, ai
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
916 KB |
Output is correct |
2 |
Correct |
96 ms |
916 KB |
Output is correct |
3 |
Correct |
94 ms |
916 KB |
Output is correct |
4 |
Incorrect |
90 ms |
916 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
916 KB |
Output is correct |
2 |
Correct |
96 ms |
916 KB |
Output is correct |
3 |
Correct |
94 ms |
916 KB |
Output is correct |
4 |
Incorrect |
90 ms |
916 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |