Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<ctime>
- #include<map>
- #include<vector>
- #include<queue>
- using namespace std;
- int main()
- {
- int n,r;
- cin>>n>>r;
- vector <int> g[n+1];
- for(int i=0;i<r;i++)
- {
- int a,b;
- cin>>a>>b;
- g[a].push_back(b);
- g[b].push_back(a);
- }
- map<vector<int>,bool> m;
- int t;
- cin>>t;
- vector <int> v;
- for(int i=0;i<t;i++)
- {
- int a,b,c;
- cin>>a>>b>>c;
- v.push_back(a);
- v.push_back(b);
- v.push_back(c);
- m[v]=true;
- v.clear();
- }
- queue<int> q;
- q.push(-1);
- q.push(0);
- q.push(0);
- bool visited[n][n];
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<n;j++)
- {
- visited[i][j]=false;
- }
- }
- while(!q.empty())
- {
- int node=q.front();
- q.pop();
- int node1=q.front();
- q.pop();
- int dis=q.front();
- q.pop();
- if(node1==(n-1))
- {
- cout<<dis;
- return 0;
- }
- for(int i=0;i<g[node1].size();i++)
- {
- int sosed=g[node1][i];
- vector <int> mapa;
- mapa.push_back(node);
- mapa.push_back(node1);
- mapa.push_back(sosed);
- if(m[mapa]==false)
- {
- if(!visited[node1][sosed])
- {
- q.push(node1);
- q.push(sosed);
- q.push(dis+1);
- visited[node1][sosed]=true;
- }
- }
- }
- }
- cout << "GRESHKA" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement