#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
#define sep ' '
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define kill(x) {cout << x << endl;return;}
#define sz(x) int(x.size())
#define SP(x) setprecision(x)
#define mod(x) (1ll*x%M+M)%M
#define pq priority_queue
#define mid (l+r)/2
// #define mid2 (l+r+1)/2
#define pll pair<ll, ll>
#define REP(i, k) for (int i = 0 ; i < k ; i ++)
#define MP make_pair
#define us unordered_set
const ll INF = 2e18;
const int N = 5e3+10;
int n, m;
ll dis[N];
vector<pair<int, pii>> E;
void add_edge(int u, int v, int w) {
E.pb({w, {v, u}});
// adj[u].pb({v, -w});
}
void solve() {
cin >> n >> m;
for(int i = 0 ; i < n ; i ++) {
add_edge(i, i+1, 0);
add_edge(i+1, i, 1);
}
for(int i = 0 ; i < m ; i ++) {
int l, r, val, k;
cin >> l >> r >> k >> val; l++, r++;
if (val == 0) {
add_edge(r, l-1, r-l+1-k);
} else {
add_edge(l-1, r, -(r-l+2-k));
}
}
fill(dis, dis+n+1, INF);
dis[0] = 0;
for(int i = 0 ; i <= n ; i ++) {
for(auto [w, e]: E) {
auto [u, v] = e;
dis[v] = min(dis[v], dis[u] + w);
}
}
for(auto [w, e]: E) {
auto [u, v] = e;
swap(u, v);
if (dis[u] > dis[v]+w) {
cout << -1 << endl;
return;
}
}
for(int i = 1 ; i <= n ; i ++) {
cout << dis[i]-dis[i-1] << sep;
}
}
// check MAXN
int32_t main() {
fastIO;
solve();
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... |