Finding simple chains of length L

Правка en1, от 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!

Теги #graph, dfs, #graphs

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Tiny924 2021-07-08 23:45:53 2 Tiny change: '100 in fout seconds.\' -> '100 in four seconds.\'
en1 Английский Tiny924 2021-07-08 23:11:12 734 Initial revision for English translation
ru1 Русский Tiny924 2021-07-08 22:37:10 731 Первая редакция (опубликовано)