循环图中的生成树总数
给定循环图中的顶点数。任务是找到可能的生成树总数。
注意:循环/圆形图是只包含一个循环的图。生成树是图中覆盖图所有顶点的最短/最小路径。
例子:
Input: Vertices = 3
Output: Total Spanning tree = 3
Input: Vertices = 4
Output: Total Spanning tree = 4
示例 1:
对于顶点 = 3 的循环图
生成树可能是 3
示例 2:
对于顶点 = 4 的循环图
生成树可能是 4
因此,生成树的数量将始终等于循环图中的顶点数。
以下是所需的实现:
C++
// C++ program to find number of
// spanning trees
#include
using namespace std;
// function that calculates the
// total Spanning tree
int Spanning(int vertices)
{
result = 0;
result = vertices;
return result;
}
// Driver code
int main()
{
int vertices = 4;
cout << "Spanning tree = " << Spanning(vertices);
return 0;
}
Java
// Java program to find number of
// spanning trees
import java.io.*;
class GFG {
// function that calculates the
// total Spanning tree
static int Spanning(int vertices)
{
int result = 0;
result = vertices;
return result;
}
// Driver code
public static void main (String[] args) {
int vertices = 4;
System.out.println("Spanning tree = " + Spanning(vertices));
}
}
// This code is contributed
// by chandan_jnu..
Python3
# Python program to find number of
# spanning trees
# function that calculates the
# total Spanning tree
def Spanning( vertices):
result = 0
result = vertices
return result
# Driver code
vertices = 4
print("Spanning tree = ",
Spanning(vertices))
# This code is contributed
# by Sanjit_Prasad
C#
// C# program to find number
// of spanning trees
using System;
// function that calculates
// the total Spanning tree
class GFG
{
public int Spanning(int vertices)
{
int result = 0;
result = vertices;
return result;
}
// Driver code
public static void Main()
{
GFG g = new GFG();
int vertices = 4;
Console.WriteLine("Spanning tree = {0}",
g.Spanning(vertices));
}
}
// This code is contributed
// by Soumik
PHP
Javascript
输出:
Spanning tree = 4