No root tree to have root Tree __ algorithm Contest Entry Classic

Source: Internet
Author: User

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);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.