Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- #define INF 1001
- vector<int> row;
- vector< vector<int> > lista(INF, row);
- vector<int> path;
- vector<int> sol;
- int telos;
- bool v[INF];
- void dfs(int start)
- {
- path.push_back(start);
- v[start]=true;
- if(start==telos)
- {
- sol=path;
- v[start]=false;
- return;
- }
- for(int i=0; i<lista[start].size(); i++)
- {
- if(v[lista[start][i]]==false)
- {
- dfs(lista[start][i]);
- }
- if(sol.size()>0)
- {
- return;
- }
- }
- v[start]=false;
- return;
- }
- int main()
- {
- int n, a, b, l, p;
- cin>>a, b, n;
- for(int i=0; i<n; i++)
- {
- cin>>l>>p;
- lista[l].push_back(p);
- }
- telos=b;
- dfs(a);
- if(sol.size()==0)
- {
- cout<<"-1"<<'\n';
- }
- else
- {
- for(int i=0; i<sol.size(); i++)
- {
- cout<<sol[i];
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement