Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- #include <conio.h>
- using namespace std;
- int n;
- bool *visited = new bool[n];
- vector <int> answer;
- int way = 0;
- int i, j;
- int pass = 0;
- int **x;
- void check(int st, int k);
- void main()
- {
- ifstream in("input.txt");
- if (in.is_open())
- {
- int count = 0;
- int temp;
- while (!in.eof())
- {
- in >> temp;
- count++;
- }
- in.seekg(0, ios::beg);
- in.clear();
- int count_space = 0;
- char symbol;
- while (!in.eof())
- {
- in.get(symbol);
- if (symbol == ' ')
- count_space++;
- if (symbol == '\n')
- break;
- }
- in.seekg(0, ios::beg);
- in.clear();
- n = count / (count_space + 1);
- int m = count_space + 1;
- x = new int*[n];
- for (int i = 0; i<n; i++)
- x[i] = new int[m];
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- in >> x[i][j];
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- cout << x[i][j] << "\t";
- cout << "\n";
- }
- in.close();
- }
- else
- {
- cout << "File did not find";
- }
- int k;
- int start;
- i = 0;
- while (i < n)
- {
- visited[i] = false;
- cout << endl;
- i++;
- }
- cout << n << endl;
- cout << "Enter starting vertex: ";
- cin >> start;
- cout << "Enter length: ";
- cin >> k;
- cout << "ways: " << endl;
- check(start - 1, k);
- cout << "searche " << way;
- delete[]visited;
- getch();
- }
- void check(int st, int k)
- {
- int i;
- visited[st] = true;
- answer.push_back(st + 1);
- for (i = 0; i < n; i++)
- {
- if ((x[st][i] == 1) && (visited[i] == false))
- {
- if ((pass + 1) != k)
- {
- pass++;
- check(i, k);
- visited[i] = false;
- }
- else
- {
- answer.push_back(i + 1);
- for (int j = 0; j < answer.size(); j++)
- {
- cout << answer[j] << " ";
- }
- way = way + 1;
- answer.erase(answer.end() - 1);
- cout << endl;
- }
- }
- }
- if (answer.size() > 1)
- {
- answer.erase(answer.end() - 1);
- }
- pass--;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement