c++

인접행렬(adjacency matrix)

주다애 2022. 9. 27. 17:30
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int map[100][100];
int node_num;
int path[5] = { 0 };

void input() {
	cin >> node_num;
	for (int i = 0; i < node_num; i++) {
		for (int j = 0; j < node_num; j++) {
			cin >> map[i][j];
		}
	}
}
void run(int num, int lev) {

	if (lev == 2) {
		for (int i = 0; i < 3; i++) {
			cout << path[i] << ' ';
		}
		cout << '\n';
		return;
	}

	for (int i = 0; i < node_num; i++) {
		if (map[num][i] == 1) {
			int next = i;
			path[lev+1] = i;
			run(next,lev+1);
			path[lev + 1] = 0;
		}
	}

}

int main() {

	path[0] = 0;
	input();
	run(0,0);

	return 0;
}

 

'c++' 카테고리의 다른 글

vector  (0) 2022.09.27