#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 - 1));
// 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 |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
788 KB |
Output is correct |
2 |
Correct |
88 ms |
788 KB |
Output is correct |
3 |
Correct |
94 ms |
788 KB |
Output is correct |
4 |
Correct |
93 ms |
788 KB |
Output is correct |
5 |
Correct |
278 ms |
916 KB |
Output is correct |
6 |
Correct |
279 ms |
912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
788 KB |
Output is correct |
2 |
Correct |
88 ms |
788 KB |
Output is correct |
3 |
Correct |
94 ms |
788 KB |
Output is correct |
4 |
Correct |
93 ms |
788 KB |
Output is correct |
5 |
Correct |
278 ms |
916 KB |
Output is correct |
6 |
Correct |
279 ms |
912 KB |
Output is correct |
7 |
Correct |
92 ms |
916 KB |
Output is correct |
8 |
Correct |
97 ms |
916 KB |
Output is correct |
9 |
Correct |
112 ms |
916 KB |
Output is correct |
10 |
Correct |
92 ms |
912 KB |
Output is correct |
11 |
Correct |
305 ms |
916 KB |
Output is correct |
12 |
Correct |
313 ms |
908 KB |
Output is correct |
13 |
Correct |
91 ms |
916 KB |
Output is correct |
14 |
Correct |
94 ms |
916 KB |
Output is correct |
15 |
Correct |
92 ms |
904 KB |
Output is correct |
16 |
Correct |
106 ms |
916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
88 ms |
788 KB |
Output is correct |
12 |
Correct |
88 ms |
788 KB |
Output is correct |
13 |
Correct |
94 ms |
788 KB |
Output is correct |
14 |
Correct |
93 ms |
788 KB |
Output is correct |
15 |
Correct |
278 ms |
916 KB |
Output is correct |
16 |
Correct |
279 ms |
912 KB |
Output is correct |
17 |
Correct |
92 ms |
916 KB |
Output is correct |
18 |
Correct |
97 ms |
916 KB |
Output is correct |
19 |
Correct |
112 ms |
916 KB |
Output is correct |
20 |
Correct |
92 ms |
912 KB |
Output is correct |
21 |
Correct |
305 ms |
916 KB |
Output is correct |
22 |
Correct |
313 ms |
908 KB |
Output is correct |
23 |
Correct |
91 ms |
916 KB |
Output is correct |
24 |
Correct |
94 ms |
916 KB |
Output is correct |
25 |
Correct |
92 ms |
904 KB |
Output is correct |
26 |
Correct |
106 ms |
916 KB |
Output is correct |
27 |
Correct |
97 ms |
908 KB |
Output is correct |
28 |
Correct |
119 ms |
916 KB |
Output is correct |
29 |
Correct |
101 ms |
980 KB |
Output is correct |
30 |
Correct |
95 ms |
940 KB |
Output is correct |
31 |
Correct |
87 ms |
972 KB |
Output is correct |
32 |
Correct |
87 ms |
916 KB |
Output is correct |
33 |
Correct |
284 ms |
920 KB |
Output is correct |
34 |
Correct |
293 ms |
972 KB |
Output is correct |
35 |
Correct |
91 ms |
916 KB |
Output is correct |
36 |
Correct |
89 ms |
916 KB |
Output is correct |