Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- #include "stdafx.h"
- #include <time.h>
- #pragma warning (disable : 4996)
- using namespace std;
- class people {
- private:
- int num;
- int **matr;
- int *visited;
- public:
- void getNum();
- void memory();
- void showMatr();
- void randomFill();
- void result();
- void dfs(int);
- };
- void people::getNum() {
- cout << "Enter the number of people: ";
- cin >> num;
- }
- void people::memory() {
- matr = new int*[num];
- for (int i = 0; i < num; i++)
- matr[i] = new int[num];
- visited = new int[num];
- }
- void people::randomFill() {
- srand((unsigned)time(NULL));
- for (int i = 0; i < num; i++)
- for (int j = 0; j < num; j++)
- if (i < j)
- matr[i][j] = rand() % 2;
- else if (i == j)
- matr[i][j] = 1;
- for (int i = 0; i < num; i++)
- for (int j = 0; j < num; j++)
- if (i > j)
- matr[i][j] = matr[j][i];
- for (int i = 0; i < num; i++)
- visited[i] = 0;
- }
- void people::showMatr() {
- for (int i = 0; i < num; i++) {
- for (int j = 0; j < num; j++)
- cout << matr[i][j] << " ";
- cout << endl;
- }
- }
- void people::dfs(int v) {
- int i;
- visited[v] = 1;
- for (int i = 0; i < num; i++)
- if (matr[i][v] && (!visited[i]))
- dfs(i);
- }
- void people::result() {
- bool temp = true;
- for (int i = 0; i < num; i++)
- if (!visited[i])
- temp = false;
- if (temp)
- cout << "We can acquaint these people.";
- else cout << "We can't acquaint these people.";
- }
- int main() {
- people People;
- People.getNum();
- People.memory();
- People.randomFill();
- People.showMatr();
- People.dfs(0);
- People.result();
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment