#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");

int a[6][6]={{0,1,1,0,1,1},
			{1,0,3,1,0,1},
			{1,3,0,1,1,0},
			{0,1,1,0,1,1},
			{1,0,1,1,0,1},
			{1,1,0,1,1,0}};
int node, edge, start, cycle[30];

void euler(int i,int index){
	cycle[index]=i;
	if(index == edge && i==start){ //i==start 생략시 오일러 경로
		for(int j=0;j<edge+1;j++)
			cout << cycle[j]+1 << " ";
		cout << endl;
	}
	else{
		for(int j=0;j<node;j++){
			if(a[i][j]>0){
				a[i][j]--;
				a[j][i]--;
				euler(j,index+1);
				a[i][j]++;
				a[j][i]++;
			}
		}
	}
}
void main(){
	node=6; edge=14; start=0;
	euler(start, 0);
}

+ Recent posts