Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<cstring>
- #include<vector>
- using namespace std;
- const int max_n=10e5;
- int start,konec,tstart,tend,prib[max_n][2],que[max_n],n,m,a,b,tain,taout;
- int head=0,tail=1,next,now;
- int ans, mans[max_n];
- vector< vector<int> > graph;
- vector< vector<int> > grin;
- vector< vector<int> > grout;
- void BFS(),dop();
- void Input()
- {
- cin >> n;
- cin >> m;
- graph.resize(n+1);
- grin.resize(n+1);
- grout.resize(n+1);
- for(int i=0;i<m;i++)
- {
- cin >> a;
- cin >> b;
- graph[a].push_back(b);
- cin >> tain >> taout;
- grin[a].push_back(tain);
- grout[a].push_back(taout);
- }
- cin >> start >> konec >> tstart >> tend;
- }
- void Solution()
- {
- for(int i=0;i<n;i++)
- prib[i][0]=(1e6)+1;
- prib[start][1]=-1;
- BFS();
- }
- void Output()
- {
- int kol=0;
- cout<<ans;
- //for(int i= ans ;i != -1;i=prib[i][1] )
- // mans[kol++]=i;
- /* cout<<kol<<"\n";
- for(int i=kol;i>=0;i--)
- {
- cout<<mans[i]<<" ";
- }
- cout<<"\n";*/
- }
- int main()
- {
- Input();
- Solution();
- Output();
- return 0;
- }
- void BFS()
- {
- que[0]=start;
- prib[start][0]=tstart;
- while( head < tail )
- {
- if(now == konec && tend >= prib[now][0]) { ans=head ; return; }
- now=que[head];
- for(int i = 0;i < graph[now].size();i++)
- {
- next=graph[now][i];
- if(prib[now][0] <= grin[now][i] ) {
- if( prib[next][0] > grout[now][i] ){
- que[tail++] = graph[now][i];
- prib[next][0] = grout[now][i];
- prib[next][1] = now;
- dop();
- }
- if( prib[graph[next][i]][0] == (1e6)+1){que[tail++]; prib[graph[next][i]][0]=grout[now][i]; prib[graph[next][i]][1]=now; }
- }
- }
- ///
- head++;
- }
- }
- void dop()
- {
- for(int i=0;i<graph[next].size();i++ )
- {
- if( prib[graph[next][i]][0] ==(1e6)+1 && prib[next][0] <= grin[next][i] ) {
- que[tail++];
- prib[graph[next][i]][1]=next;
- prib[graph[next][i]][0]=grout[next][i];
- }
- }
- }
Add Comment
Please, Sign In to add comment