-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob_00677.cpp
52 lines (48 loc) · 1.2 KB
/
prob_00677.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vi>
#define vvii vector<vii>
#define ll long long
#define sc(n) scanf("%d",&n)
#define scc(n,m) scanf("%d%d",&n,&m)
#define repf(i,a,b) for(i=a;i<b;++i)
vector<vector<bool> > matrix(15,vector<bool>(15));
int m,n;
vector<int> nodes(15);
vector<bool> visited(15);
bool flag=false;
void print_n_walks(int src,int dist){
if(dist==m){
flag=true;
printf("(%d",nodes[0]);
for(int i=1;i<=m;i++) printf(",%d",nodes[i]);
printf(")\n");
}else{
for(int i=0;i<n;++i){
if(matrix[src][i] && !visited[i]){
visited[i]=true;
nodes[dist+1]=i+1;
print_n_walks(i,dist+1);
visited[i]=false;
}
}
}
}
int main(){
int i,j,k,l;
while(cin>> n >> m){
repf(i,0,n)
repf(j,0,n)
sc(k),matrix[i][j]=k;
visited.assign(n,false);
visited[0]=1, nodes[0]=1;
flag=false;
print_n_walks(0,0);
if(!flag)
printf("no walk of length %d\n",m);
if(sc(n)!=EOF)
printf("\n");
}
}