#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991
const int maxn = 1000001;
int dist[maxn];
vector<array<int, 3>> E;
signed main () {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
for (int i = 0 ; i < m ; i++) {
int x, y, k, v;
cin >> x >> y >> k >> v;
x++,y++;
int s = y - x + 1;
if (v == 1) {
k--;
E.push_back({x - 1, y, k - s});
} else {
E.push_back({y, x - 1, s - k});
}
}
for (int i = 1 ; i <= n ; i++) dist[i] = INT_MAX;
for (int i = 0 ; i < n ; i++) {
E.push_back({i, i + 1, 0});
E.push_back({i + 1, i, 1});
}
for (int iter = 0 ; iter < n ; iter++) {
for (auto [u,v,w] : E) {
if (dist[v] != INT_MAX)
dist[u] = min(dist[u], dist[v] + w);
}
}
bool imp = 0;
for (auto [u,v,w] : E) {
if (dist[u] != INT_MAX && dist[u] > dist[v] + w) imp = 1;
}
if (imp) cout << -1;
else {
for (int i = 1 ; i <= n ; i++) {
cout << (dist[i] > dist[i-1]) << " ";
}
}
}
Compilation message
restore.cpp:17:1: warning: multi-line comment [-Wcomment]
17 | //\
| ^
restore.cpp: In function 'int main()':
restore.cpp:53:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
53 | for (auto [u,v,w] : E) {
| ^
restore.cpp:61:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
61 | for (auto [u,v,w] : E) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
322 ms |
1232 KB |
Output is correct |
2 |
Correct |
329 ms |
1232 KB |
Output is correct |
3 |
Correct |
326 ms |
1232 KB |
Output is correct |
4 |
Correct |
336 ms |
1232 KB |
Output is correct |
5 |
Correct |
330 ms |
1232 KB |
Output is correct |
6 |
Correct |
329 ms |
1232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
322 ms |
1232 KB |
Output is correct |
2 |
Correct |
329 ms |
1232 KB |
Output is correct |
3 |
Correct |
326 ms |
1232 KB |
Output is correct |
4 |
Correct |
336 ms |
1232 KB |
Output is correct |
5 |
Correct |
330 ms |
1232 KB |
Output is correct |
6 |
Correct |
329 ms |
1232 KB |
Output is correct |
7 |
Correct |
337 ms |
1232 KB |
Output is correct |
8 |
Correct |
334 ms |
1232 KB |
Output is correct |
9 |
Correct |
328 ms |
1232 KB |
Output is correct |
10 |
Correct |
338 ms |
1232 KB |
Output is correct |
11 |
Correct |
324 ms |
1232 KB |
Output is correct |
12 |
Correct |
341 ms |
1232 KB |
Output is correct |
13 |
Correct |
317 ms |
1212 KB |
Output is correct |
14 |
Correct |
350 ms |
1232 KB |
Output is correct |
15 |
Correct |
342 ms |
1232 KB |
Output is correct |
16 |
Correct |
355 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
322 ms |
1232 KB |
Output is correct |
12 |
Correct |
329 ms |
1232 KB |
Output is correct |
13 |
Correct |
326 ms |
1232 KB |
Output is correct |
14 |
Correct |
336 ms |
1232 KB |
Output is correct |
15 |
Correct |
330 ms |
1232 KB |
Output is correct |
16 |
Correct |
329 ms |
1232 KB |
Output is correct |
17 |
Correct |
337 ms |
1232 KB |
Output is correct |
18 |
Correct |
334 ms |
1232 KB |
Output is correct |
19 |
Correct |
328 ms |
1232 KB |
Output is correct |
20 |
Correct |
338 ms |
1232 KB |
Output is correct |
21 |
Correct |
324 ms |
1232 KB |
Output is correct |
22 |
Correct |
341 ms |
1232 KB |
Output is correct |
23 |
Correct |
317 ms |
1212 KB |
Output is correct |
24 |
Correct |
350 ms |
1232 KB |
Output is correct |
25 |
Correct |
342 ms |
1232 KB |
Output is correct |
26 |
Correct |
355 ms |
1236 KB |
Output is correct |
27 |
Correct |
324 ms |
1232 KB |
Output is correct |
28 |
Correct |
349 ms |
1232 KB |
Output is correct |
29 |
Correct |
327 ms |
1232 KB |
Output is correct |
30 |
Correct |
350 ms |
1232 KB |
Output is correct |
31 |
Correct |
323 ms |
1232 KB |
Output is correct |
32 |
Correct |
332 ms |
1232 KB |
Output is correct |
33 |
Correct |
346 ms |
1320 KB |
Output is correct |
34 |
Correct |
321 ms |
1232 KB |
Output is correct |
35 |
Correct |
337 ms |
1232 KB |
Output is correct |
36 |
Correct |
323 ms |
1216 KB |
Output is correct |