#include <bits/stdc++.h>
#define DIM 10010
#define INF 2000000000
using namespace std;
vector <pair<int,int> > L[DIM];
deque <int> c;
int viz[DIM],sp[DIM],w[DIM];
int n,m,i,j,x,y,k,val;
void add_edge (int x, int y, int cost){
L[x].push_back(make_pair(y,cost));
//cout<<x<<" "<<y<<" "<<cost<<"\n";
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>m;
for (i=1;i<=m;i++){
cin>>x>>y>>k>>val;
x++, y++;
if (val)
add_edge(x-1,y,k-1);
else add_edge(y,x-1,-k);
}
for (i=1;i<=n;i++){
add_edge(i-1,i,1);
add_edge(i,i-1,0);
sp[i] = INF;
}
c.push_back(0);
viz[0] = 1;
sp[0] = 1;
while (!c.empty()){
int nod = c.front();
c.pop_front();
viz[nod] = 0;
for (auto it : L[nod]){
int vecin = it.first, cost = it.second;
if (sp[nod] + cost < sp[vecin]){
sp[vecin] = sp[nod] + cost;
if (sp[vecin] < 0){
cout<<"-1";
return 0;
}
if (!viz[vecin]){
viz[vecin] = 1;
c.push_back(vecin);
w[vecin]++;
if (w[vecin] > n){
cout<<"-1";
return 0;
}}}}}
for (i=1;i<=n;i++){
if (sp[i] == sp[i-1])
cout<<"1 ";
else cout<<"0 ";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
536 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
832 KB |
Output is correct |
2 |
Correct |
11 ms |
972 KB |
Output is correct |
3 |
Correct |
10 ms |
936 KB |
Output is correct |
4 |
Correct |
11 ms |
932 KB |
Output is correct |
5 |
Correct |
9 ms |
916 KB |
Output is correct |
6 |
Correct |
9 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
832 KB |
Output is correct |
2 |
Correct |
11 ms |
972 KB |
Output is correct |
3 |
Correct |
10 ms |
936 KB |
Output is correct |
4 |
Correct |
11 ms |
932 KB |
Output is correct |
5 |
Correct |
9 ms |
916 KB |
Output is correct |
6 |
Correct |
9 ms |
972 KB |
Output is correct |
7 |
Correct |
18 ms |
1068 KB |
Output is correct |
8 |
Correct |
17 ms |
1072 KB |
Output is correct |
9 |
Correct |
17 ms |
984 KB |
Output is correct |
10 |
Correct |
24 ms |
972 KB |
Output is correct |
11 |
Correct |
10 ms |
972 KB |
Output is correct |
12 |
Correct |
10 ms |
956 KB |
Output is correct |
13 |
Correct |
17 ms |
1052 KB |
Output is correct |
14 |
Correct |
35 ms |
972 KB |
Output is correct |
15 |
Correct |
81 ms |
1060 KB |
Output is correct |
16 |
Correct |
89 ms |
1020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
536 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
9 ms |
832 KB |
Output is correct |
12 |
Correct |
11 ms |
972 KB |
Output is correct |
13 |
Correct |
10 ms |
936 KB |
Output is correct |
14 |
Correct |
11 ms |
932 KB |
Output is correct |
15 |
Correct |
9 ms |
916 KB |
Output is correct |
16 |
Correct |
9 ms |
972 KB |
Output is correct |
17 |
Correct |
18 ms |
1068 KB |
Output is correct |
18 |
Correct |
17 ms |
1072 KB |
Output is correct |
19 |
Correct |
17 ms |
984 KB |
Output is correct |
20 |
Correct |
24 ms |
972 KB |
Output is correct |
21 |
Correct |
10 ms |
972 KB |
Output is correct |
22 |
Correct |
10 ms |
956 KB |
Output is correct |
23 |
Correct |
17 ms |
1052 KB |
Output is correct |
24 |
Correct |
35 ms |
972 KB |
Output is correct |
25 |
Correct |
81 ms |
1060 KB |
Output is correct |
26 |
Correct |
89 ms |
1020 KB |
Output is correct |
27 |
Correct |
13 ms |
1068 KB |
Output is correct |
28 |
Correct |
12 ms |
1076 KB |
Output is correct |
29 |
Correct |
13 ms |
972 KB |
Output is correct |
30 |
Correct |
13 ms |
980 KB |
Output is correct |
31 |
Correct |
12 ms |
960 KB |
Output is correct |
32 |
Correct |
12 ms |
972 KB |
Output is correct |
33 |
Correct |
11 ms |
972 KB |
Output is correct |
34 |
Correct |
11 ms |
972 KB |
Output is correct |
35 |
Correct |
13 ms |
1092 KB |
Output is correct |
36 |
Correct |
13 ms |
972 KB |
Output is correct |