#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll maxn = 6000, maxm = 2e4;
const ll mod = 1e9 + 7;
const ll inf = 2e9;
#define TextIO ifstream fileIn("input.txt"); cin.rdbuf(fileIn.rdbuf()); ofstream fileOut("output.txt"); cout.rdbuf(fileOut.rdbuf());
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define print(x) for (auto i : x) cout << i << ' '; cout << endl
#define out(x) {cout << x << endl; return;}
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll pw(ll a, ll b, ll md = mod) {ll res = 1; b = max(b, 0ll); while(b) {if (b & 1){res = (a * res) % md;} a = (a * a) % md; b >>= 1;} return (res % md);}
int n, m;
struct {int u, v, w;} E[maxm];
int d[maxn][maxn];
int vis[maxn];
void solve() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int l, r, k, x;
cin >> l >> r >> k >> x;
l++, r++;
if (x == 1) E[i] = {r, l - 1, k - (r - l + 1) - 1};
else E[i] = {l - 1, r, (r - l + 1) - k};
}
for (int i = 1; i <= n; i++)
E[i + m] = {i - 1, i, 1};
m += n;
for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) d[i][j] = inf;
for (int i = 0; i <= n; i++) d[0][i] = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
d[E[j].v][i] = min({d[E[j].v][i - 1], d[E[j].u][i - 1] + E[j].w, d[E[j].v][i]});
vector<int> ans;
for (int i = 1; i <= n; i++) {
ans.pb(d[i][n - 1] - d[i - 1][n - 1]);
if (d[i][n - 1] - d[i - 1][n - 1] > 1 || d[i][n - 1] - d[i - 1][n - 1] < 0) out(-1);
}
print(ans);
}
int main() {
FastIO
ll t = 1;
// cin >> t;
while (t--)
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... |