/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 5002;
const int M_MAX = 10002;
int n, m;
struct Edge
{
int u;
int len;
};
vector <Edge> edges[N_MAX];
void addMinDiff (int u, int v, int d)
{
edges[u].push_back(Edge{v, -d});
}
void addMaxDiff (int u, int v, int d)
{
edges[v].push_back(Edge{u, d});
}
int dist[N_MAX];
queue <int> q;
int times[N_MAX];
bool inq[N_MAX];
bool BellmanFord ()
{
for(int i = 0; i <= n; i++)
dist[i] = INT_MAX;
dist[0] = 0;
inq[0] = true;
q.push(0);
while(q.empty() == false)
{
int u = q.front();
q.pop();
inq[u] = false;
for(Edge &e : edges[u])
if(dist[u] + e.len < dist[e.u])
{
dist[e.u] = dist[u] + e.len;
if(dist[e.u] < 0)
return false;
if(inq[e.u] == false)
{
q.push(e.u);
inq[e.u] = true;
}
}
}
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
addMinDiff(i, i - 1, 0);
addMaxDiff(i, i - 1, 1);
}
for(int i = 1; i <= m; i++)
{
int l, r, k;
bool val;
cin >> l >> r >> k >> val;
l++;
r++;
if(val == 0)
addMinDiff(r, l - 1, k);
else
addMaxDiff(r, l - 1, k - 1);
}
if(BellmanFord() == true)
{
for(int i = 1; i <= n; i++)
cout << 1 - (dist[i] - dist[i - 1]) << " ";
cout << "\n";
}
else
cout << "-1\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1004 KB |
Output is correct |
2 |
Correct |
7 ms |
1004 KB |
Output is correct |
3 |
Correct |
5 ms |
1004 KB |
Output is correct |
4 |
Correct |
6 ms |
1004 KB |
Output is correct |
5 |
Correct |
5 ms |
1004 KB |
Output is correct |
6 |
Correct |
5 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1004 KB |
Output is correct |
2 |
Correct |
7 ms |
1004 KB |
Output is correct |
3 |
Correct |
5 ms |
1004 KB |
Output is correct |
4 |
Correct |
6 ms |
1004 KB |
Output is correct |
5 |
Correct |
5 ms |
1004 KB |
Output is correct |
6 |
Correct |
5 ms |
1004 KB |
Output is correct |
7 |
Correct |
13 ms |
1060 KB |
Output is correct |
8 |
Correct |
12 ms |
1004 KB |
Output is correct |
9 |
Correct |
12 ms |
1132 KB |
Output is correct |
10 |
Correct |
19 ms |
1004 KB |
Output is correct |
11 |
Correct |
5 ms |
1004 KB |
Output is correct |
12 |
Correct |
5 ms |
1004 KB |
Output is correct |
13 |
Correct |
17 ms |
1004 KB |
Output is correct |
14 |
Correct |
31 ms |
1004 KB |
Output is correct |
15 |
Correct |
83 ms |
1004 KB |
Output is correct |
16 |
Correct |
95 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
5 ms |
1004 KB |
Output is correct |
12 |
Correct |
7 ms |
1004 KB |
Output is correct |
13 |
Correct |
5 ms |
1004 KB |
Output is correct |
14 |
Correct |
6 ms |
1004 KB |
Output is correct |
15 |
Correct |
5 ms |
1004 KB |
Output is correct |
16 |
Correct |
5 ms |
1004 KB |
Output is correct |
17 |
Correct |
13 ms |
1060 KB |
Output is correct |
18 |
Correct |
12 ms |
1004 KB |
Output is correct |
19 |
Correct |
12 ms |
1132 KB |
Output is correct |
20 |
Correct |
19 ms |
1004 KB |
Output is correct |
21 |
Correct |
5 ms |
1004 KB |
Output is correct |
22 |
Correct |
5 ms |
1004 KB |
Output is correct |
23 |
Correct |
17 ms |
1004 KB |
Output is correct |
24 |
Correct |
31 ms |
1004 KB |
Output is correct |
25 |
Correct |
83 ms |
1004 KB |
Output is correct |
26 |
Correct |
95 ms |
1132 KB |
Output is correct |
27 |
Correct |
8 ms |
1004 KB |
Output is correct |
28 |
Correct |
8 ms |
1004 KB |
Output is correct |
29 |
Correct |
10 ms |
1004 KB |
Output is correct |
30 |
Correct |
11 ms |
1004 KB |
Output is correct |
31 |
Correct |
10 ms |
1004 KB |
Output is correct |
32 |
Correct |
8 ms |
1004 KB |
Output is correct |
33 |
Correct |
6 ms |
1004 KB |
Output is correct |
34 |
Correct |
5 ms |
1024 KB |
Output is correct |
35 |
Correct |
9 ms |
1004 KB |
Output is correct |
36 |
Correct |
8 ms |
1004 KB |
Output is correct |