Skip to content

Instantly share code, notes, and snippets.

@Luoyayu
Last active January 3, 2018 05:39
Show Gist options
  • Save Luoyayu/e14015f493157dd52dadea23cd65cdd1 to your computer and use it in GitHub Desktop.
Save Luoyayu/e14015f493157dd52dadea23cd65cdd1 to your computer and use it in GitHub Desktop.
print_all_simple_path
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
vector<int> ans, g[maxn];
bool vis[maxn];
void dfs(vector<int>p, int cur, int t) {
p.push_back(cur);
vis[cur] = 1;
if (cur == t) {
for (auto x:p) printf("%d ", x);
puts("");
}
for (auto x:g[cur])
if (!vis[x]) dfs(p, x, t);
vis[cur] = 0;
}
int main() {
int m;
while (scanf("%d", &m) != EOF) {
for (int i = 0; i < maxn; i++) vis[i] = 0, g[i].clear();
while (m--) {
int u, v;
scanf("%d %d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
}
int s, e;
scanf("%d%d", &s, &e);
dfs(ans, s, e);
}
}
/*
input:
12
1 2
2 3
2 5
4 2
5 11
11 12
6 7
5 6
3 6
6 8
8 10
8 9
1 7
12
1 2
1 6
1 7
2 7
6 7
6 5
2 3
3 7
3 4
4 5
4 7
5 7
1 4
output:
1 2 3 6 7
1 2 5 6 7
1 2 7 6 5 4
1 2 7 3 4
1 2 7 4
1 2 7 5 4
1 2 3 7 6 5 4
1 2 3 7 4
1 2 3 7 5 4
1 2 3 4
1 6 7 2 3 4
1 6 7 3 4
1 6 7 4
1 6 7 5 4
1 6 5 4
1 6 5 7 2 3 4
1 6 5 7 3 4
1 6 5 7 4
1 7 2 3 4
1 7 6 5 4
1 7 3 4
1 7 4
1 7 5 4
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment