/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 10010;
const ll inf = 1e15;
struct edge
{
int v, u;
ll w;
edge(int _v = 0, int _u = 0, ll _w = 0)
{
v = _v;
u = _u;
w = _w;
}
};
vector < edge > e;
int n, m;
ll d[maxn];
void solve()
{
cin >> n >> m;
for (int i = 1; i <= m; i ++)
{
int l, r, k, v;
cin >> l >> r >> k >> v;
l ++;
r ++;
if (v == 0)
{
e.push_back(edge(l - 1, r, r - l + 1 - k));
}
else
{
e.push_back(edge(r, l - 1, - k));
}
}
for (int i = 1; i <= n; i ++)
{
e.push_back(edge(i - 1, i, 1));
}
e.push_back(edge(0, 0, 0));
int last = -1;
for (int step = 1; step <= n; step ++)
{
int x = -1;
for (edge ed : e)
{
if (d[ed.v] + ed.w < d[ed.u])
{
d[ed.u] = max(- inf, d[ed.v] + ed.w);
x = ed.u;
}
}
last = x;
}
if (last == -1)
cout << -1 << endl;
else
{
for (int i = 0; i <= n + 1; i ++)
d[i] = inf;
for (int i = 0; i <= n; i ++)
{
e.push_back(edge(n + 1, i, 0));
}
d[n + 1] = 0;
for (int step = 1; step < n; step ++)
{
for (edge ed : e)
{
if (d[ed.v] < inf && d[ed.v] + ed.w < d[ed.u])
{
d[ed.u] = d[ed.v] + ed.w;
}
}
}
for (int i = 1; i <= n; i ++)
cout << d[i] - d[i - 1] << " ";
cout << endl;
}
}
int main()
{
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |