代码

Jerry_Zhou  •  2年前


#include<bits/stdc++.h>
using namespace std;

int n,a[105][105],stk[105],m[105],k,top;
int main(){
    cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
		}
	}
	stk[++top]=1;
	m[1]=1;
	cout<<1;
	while(top>0){
		k++;
		if(k>n) k=stk[top--];
		else if(a[stk[top]][k]&&!m[k]){
			cout<<"-"<<k;
			stk[++top]=k;
			m[k]=1;
			k=0;
		}
	}
	cout<<endl;
	//system("pause");
	return 0;
} 

评论:

请先登录,才能进行评论