#include <bits/stdc++.h>
using namespace std;
int n,m,i,j,st,dr,val,k,dist[50005],cnt_push[50005];
vector <pair <int,int> > gr[50000];
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(0);
#ifdef HOME
ifstream cin("date.in");
ofstream cout("date.out");
#endif // HOME
cin>>n>>m;
for (i=1;i<=m;i++)
{
cin>>st>>dr>>k>>val;
st++;
dr++;
if (val==0)
{
k=dr-st+1-k;
gr[st-1].push_back({dr,k});
}
else
{
k=dr-st+1-k+1;
gr[dr].push_back({st-1,-k});
}
}
for (i=0;i<=n;i++)
{
dist[i]=1e9;
}
for (i=1;i<=n;i++)
{
gr[i].push_back({i-1,0});
gr[i-1].push_back({i,1});
}
queue <int> q;
q.push(0);
dist[0]=0;
while (!q.empty())
{
int node=q.front();
q.pop();
for (int i=0;i<gr[node].size();i++)
{
int x=gr[node][i].first;
if (dist[node]+gr[node][i].second<dist[x])
{
dist[x]=dist[node]+gr[node][i].second;
if (++cnt_push[x]>n)
{
cout<<"-1";
exit(0);
}
q.push(x);
}
}
}
for (i=1;i<=n;i++)
{
cout<<dist[i]-dist[i-1]<<" ";
}
return 0;
}
Compilation message
restore.cpp: In function 'int main()':
restore.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i=0;i<gr[node].size();i++)
| ~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1484 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1484 KB |
Output is correct |
8 |
Correct |
1 ms |
1484 KB |
Output is correct |
9 |
Correct |
1 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1740 KB |
Output is correct |
2 |
Correct |
15 ms |
1836 KB |
Output is correct |
3 |
Correct |
13 ms |
1740 KB |
Output is correct |
4 |
Correct |
12 ms |
1832 KB |
Output is correct |
5 |
Correct |
543 ms |
24572 KB |
Output is correct |
6 |
Correct |
581 ms |
24600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1740 KB |
Output is correct |
2 |
Correct |
15 ms |
1836 KB |
Output is correct |
3 |
Correct |
13 ms |
1740 KB |
Output is correct |
4 |
Correct |
12 ms |
1832 KB |
Output is correct |
5 |
Correct |
543 ms |
24572 KB |
Output is correct |
6 |
Correct |
581 ms |
24600 KB |
Output is correct |
7 |
Correct |
16 ms |
2020 KB |
Output is correct |
8 |
Correct |
14 ms |
2000 KB |
Output is correct |
9 |
Correct |
20 ms |
2040 KB |
Output is correct |
10 |
Correct |
13 ms |
2000 KB |
Output is correct |
11 |
Correct |
579 ms |
25400 KB |
Output is correct |
12 |
Correct |
534 ms |
25064 KB |
Output is correct |
13 |
Correct |
13 ms |
2000 KB |
Output is correct |
14 |
Correct |
24 ms |
2040 KB |
Output is correct |
15 |
Correct |
34 ms |
2032 KB |
Output is correct |
16 |
Correct |
112 ms |
2000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1484 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1484 KB |
Output is correct |
8 |
Correct |
1 ms |
1484 KB |
Output is correct |
9 |
Correct |
1 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1484 KB |
Output is correct |
11 |
Correct |
13 ms |
1740 KB |
Output is correct |
12 |
Correct |
15 ms |
1836 KB |
Output is correct |
13 |
Correct |
13 ms |
1740 KB |
Output is correct |
14 |
Correct |
12 ms |
1832 KB |
Output is correct |
15 |
Correct |
543 ms |
24572 KB |
Output is correct |
16 |
Correct |
581 ms |
24600 KB |
Output is correct |
17 |
Correct |
16 ms |
2020 KB |
Output is correct |
18 |
Correct |
14 ms |
2000 KB |
Output is correct |
19 |
Correct |
20 ms |
2040 KB |
Output is correct |
20 |
Correct |
13 ms |
2000 KB |
Output is correct |
21 |
Correct |
579 ms |
25400 KB |
Output is correct |
22 |
Correct |
534 ms |
25064 KB |
Output is correct |
23 |
Correct |
13 ms |
2000 KB |
Output is correct |
24 |
Correct |
24 ms |
2040 KB |
Output is correct |
25 |
Correct |
34 ms |
2032 KB |
Output is correct |
26 |
Correct |
112 ms |
2000 KB |
Output is correct |
27 |
Correct |
8 ms |
2128 KB |
Output is correct |
28 |
Correct |
8 ms |
2000 KB |
Output is correct |
29 |
Correct |
7 ms |
2000 KB |
Output is correct |
30 |
Correct |
8 ms |
2000 KB |
Output is correct |
31 |
Correct |
7 ms |
2000 KB |
Output is correct |
32 |
Correct |
8 ms |
2000 KB |
Output is correct |
33 |
Correct |
564 ms |
25884 KB |
Output is correct |
34 |
Correct |
562 ms |
26164 KB |
Output is correct |
35 |
Correct |
9 ms |
2000 KB |
Output is correct |
36 |
Correct |
9 ms |
2000 KB |
Output is correct |