In discrete mathematics, no-root tree refers to non-ring connected undirected graphs.
A tree without root is a two-tuple (v,e), of which: 1. V is a non-empty set, called a vertex set. 2.E is a set of unordered two-tuple groups of elements in V, called Edge sets.
Intuitively, if each edge of a graph is a direction-free, it is called a directed graph. Edges in a freeform graph are unordered pairs of vertices, usually expressed in parentheses. No root tree it requires that each vertex is connected directly or indirectly, and there is no ring in the diagram, that is, only a simple path.
Because the tree is a subset of the graph, this kind of graph has the characteristic of the tree, but does not have the tree form, does not have the specific root node, therefore is called the tree without root.
Any selection of a point in the graph is rooted, can transform the root tree into a root tree.
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
Vector<int> v[100];
int p[100];
void Dfs (int p1, int p2)
{for
(int i = 0; i < v[p1].size (); i++)
{
int h = v[p1][i];
if (H!= p2) dfs (h, p[h] = p1);
}
int main ()
{
int root, n;
Cin >> root >> N;
for (int i = 1; i < n; i++)//n fixed-point has n-1 bar edge
{
int a, b;
Cin >> a >> b;
V[a].push_back (b);
V[b].push_back (a);
}
P[root] =-1;
DFS (Root,-1);
}