#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MAXN = 100000;
int dist[MAXN+5];
const int INF = 1000000000;
int ea[MAXN+5];
int eb[MAXN+5];
int ec[MAXN+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, m;
cin >> n >> m;
for(int i=1; i<=m; i++){
int l, r, k, val;
cin >> l >> r >> k >> val;
l++;
r++;
if(val == 1){
ea[i] = l-1;
eb[i] = r;
ec[i] = k-1;
}
else{
ea[i] = r;
eb[i] = l-1;
ec[i] = -k;
}
}
for(int i=1; i<=n; i++){
m++;
ea[m] = i-1;
eb[m] = i;
ec[m] = 1;
m++;
ea[m] = i;
eb[m] = i-1;
ec[m] = 0;
}
for(int i=1; i<=n; i++) dist[i] = INF;
for(int k=0; k<n; k++){
for(int j=1; j<=m; j++){
int a = ea[j];
int b = eb[j];
int c = ec[j];
if(dist[b] > dist[a] + c){
dist[b] = dist[a] + c;
if(dist[b] < 0){
cout << "-1\n";
return 0;
}
}
}
}
for(int j=1; j<=m; j++){
int a = ea[j];
int b = eb[j];
int c = ec[j];
if(dist[b] > dist[a] + c){
cout << "-1\n";
return 0;
}
}
for(int i=1; i<=n; i++){
cout << (1^(dist[i] - dist[i-1])) << " ";
}
cout << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
460 KB |
Output is correct |
2 |
Correct |
128 ms |
552 KB |
Output is correct |
3 |
Correct |
128 ms |
556 KB |
Output is correct |
4 |
Correct |
130 ms |
572 KB |
Output is correct |
5 |
Correct |
4 ms |
460 KB |
Output is correct |
6 |
Correct |
4 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
460 KB |
Output is correct |
2 |
Correct |
128 ms |
552 KB |
Output is correct |
3 |
Correct |
128 ms |
556 KB |
Output is correct |
4 |
Correct |
130 ms |
572 KB |
Output is correct |
5 |
Correct |
4 ms |
460 KB |
Output is correct |
6 |
Correct |
4 ms |
588 KB |
Output is correct |
7 |
Correct |
130 ms |
712 KB |
Output is correct |
8 |
Correct |
131 ms |
716 KB |
Output is correct |
9 |
Correct |
134 ms |
716 KB |
Output is correct |
10 |
Correct |
129 ms |
692 KB |
Output is correct |
11 |
Correct |
5 ms |
716 KB |
Output is correct |
12 |
Correct |
4 ms |
716 KB |
Output is correct |
13 |
Correct |
130 ms |
708 KB |
Output is correct |
14 |
Correct |
136 ms |
716 KB |
Output is correct |
15 |
Correct |
146 ms |
716 KB |
Output is correct |
16 |
Correct |
141 ms |
808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
127 ms |
460 KB |
Output is correct |
12 |
Correct |
128 ms |
552 KB |
Output is correct |
13 |
Correct |
128 ms |
556 KB |
Output is correct |
14 |
Correct |
130 ms |
572 KB |
Output is correct |
15 |
Correct |
4 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
588 KB |
Output is correct |
17 |
Correct |
130 ms |
712 KB |
Output is correct |
18 |
Correct |
131 ms |
716 KB |
Output is correct |
19 |
Correct |
134 ms |
716 KB |
Output is correct |
20 |
Correct |
129 ms |
692 KB |
Output is correct |
21 |
Correct |
5 ms |
716 KB |
Output is correct |
22 |
Correct |
4 ms |
716 KB |
Output is correct |
23 |
Correct |
130 ms |
708 KB |
Output is correct |
24 |
Correct |
136 ms |
716 KB |
Output is correct |
25 |
Correct |
146 ms |
716 KB |
Output is correct |
26 |
Correct |
141 ms |
808 KB |
Output is correct |
27 |
Correct |
129 ms |
704 KB |
Output is correct |
28 |
Correct |
130 ms |
716 KB |
Output is correct |
29 |
Correct |
130 ms |
716 KB |
Output is correct |
30 |
Correct |
132 ms |
836 KB |
Output is correct |
31 |
Correct |
127 ms |
708 KB |
Output is correct |
32 |
Correct |
131 ms |
716 KB |
Output is correct |
33 |
Correct |
4 ms |
716 KB |
Output is correct |
34 |
Correct |
4 ms |
720 KB |
Output is correct |
35 |
Correct |
131 ms |
724 KB |
Output is correct |
36 |
Correct |
132 ms |
716 KB |
Output is correct |