Tiny924's blog

By Tiny924, history, 3 years ago, translation, In English

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 four 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!

  • Vote: I like it
  • +3
  • Vote: I do not like it

| Write comment?