Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long int lli;
- int m[1001][1001],t[1001][1001],vis[1001][1001];
- int c,d;
- int dx[4]= {-1,0,0,1};
- int dy[4]= {0,-1,1,0};
- void bfs(int sx,int sy)
- {
- int ux,uy,vx,vy;
- queue<int>q;
- q.push(sx);
- q.push(sy);
- vis[sx][sy]=1;
- while(!q.empty())
- {
- ux=q.front();
- q.pop();
- uy=q.front();
- q.pop();
- for(int k=0; k<4; k++)
- {
- vx=ux+dx[k];
- vy=uy+dy[k];
- if((vx>=0)&&(vx<=c)&&(vy>=0)&&(vy<=d)&&(!m[vx][vy])&&(!vis[vx][vy]))
- {
- q.push(vx);
- q.push(vy);
- vis[vx][vy]=1;
- t[vx][vy]=t[ux][uy]+1;
- }
- }
- }
- }
- int main()
- {
- int e,row,mine,nom,sx,sy,ex,ey,ga,gb;
- cin>>c>>d>>e;
- while(e--)
- {
- cin>>row>>nom;
- for(int i=1; i<=nom; i++)
- {
- cin>>mine;
- m[row][mine]=1;
- }
- }
- cin>>sx>>sy;
- bfs(sx,sy);
- cin>>ex>>ey;
- cin>>ga>>gb;
- cout<<t[ex][ey]<<endl;
- /*for(int i=0; i<c; i++)
- {
- for(int j=0; j<d; j++)
- {
- cout<<vis[i][j]<<" ";
- }
- cout<<endl;
- }*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement