이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<deque>
using namespace std;
int Nr0[5005]; //cate valori 0 am in [1,i]
int NrInQ[5005],InQ[5005];
vector<pair<int,int> > A[5005]; //(x,y,c) = Nr0[y]<=Nr0[x]+c
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=1; i<=m; i++)
{
int st,dr,k,val;
cin>>st>>dr>>k>>val;
st++;
dr++;
if(val==0)
A[dr].push_back({st-1,-k});
else
A[st-1].push_back({dr,k-1});
}
for(int i=1; i<=n; i++)
{
A[i-1].push_back({i,1});
A[i].push_back({i-1,0});
Nr0[i]=1000000000;
}
deque<int> Q;
Q.push_back(0);
InQ[0]=1;
NrInQ[0]=1;
while(!Q.empty())
{
int nod=Q.front();
Q.pop_front();
InQ[nod]=0;
for(auto other:A[nod])
{
if(Nr0[other.first]>Nr0[nod]+other.second)
{
Nr0[other.first]=Nr0[nod]+other.second;
NrInQ[other.first]++;
if(NrInQ[other.first]>n || Nr0[other.first]<0)
{
cout<<"-1\n";
return 0;
}
if(InQ[other.first])
continue;
Q.push_back(other.first);
InQ[other.first]=1;
}
}
}
for(int i=1; i<=n; i++)
{
if(Nr0[i]!=Nr0[i-1])
cout<<"0 ";
else
cout<<"1 ";
}
cout<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |