Finding simple chains of length L

Revision en1, by Tiny924, 2021-07-08 23:11:12

Hi, everyone! I cant find how to calc number of simple chains lengths n in graph(or just calc all simple chains). Find only this(on russian), but i think that this won't work for N = 100 in fout seconds. I could only think of for launching DFS from every vertex and for each path pass his own set of used vertex:

void dfs(short int st, short int dist, vector<bool> used) {
	if (dist >= 7) {//In my task i need to find all chains of length 7
		++ans;
		return;
	}
	for (auto r : g[st]) {
		if (!used[r]) {
			used[r] = 1;
			dfs(r, dist + 1, used);
			used[r] = 0;
		}
	}
}

Thanks for help!

Tags #graph, dfs, #graphs

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Tiny924 2021-07-08 23:45:53 2 Tiny change: '100 in fout seconds.\' -> '100 in four seconds.\'
en1 English Tiny924 2021-07-08 23:11:12 734 Initial revision for English translation
ru1 Russian Tiny924 2021-07-08 22:37:10 731 Первая редакция (опубликовано)