๐Ÿ“ฆ gopikrishna000 / templates-latest

๐Ÿ“„ floyd_cycle.cpp ยท 33 lines
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<snippet>
	<content><![CDATA[


//cycled finding in floyd grapg [hanging tree like structure]
		vi brr(n), vis(n);
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (!vis[i]) {
				int j = i;
				int c = 0;
				si s;
				while (!vis[j]) {
					s.insert(j);
					vis[j] = 1;
					brr[j] = c;
					j = arr[j];
					c++;
				}
				wd(c, j, brr[j], i);
				if (s.find(j) != s.end())
					ans += c - brr[j];

			}
		}

]]></content>
	<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
	<tabTrigger>floyd cycles hanging</tabTrigger>
	<!-- Optional: Set a scope to limit where the snippet will trigger -->
	<scope>source.c++</scope>
</snippet>