[Tree structure] No root tree to a root tree, no root tree to a root tree
// Enter n number of nodes in the rootless tree, n-1 edge (u, v), and root number of the root to be specified, create a root-root tree/* variable-length array. An array with the length of each row of maxn rows can be used to indicate the relationship between nodes in the tree */# include <stdio. h> # include <stdlib. h> # include <string. h >#include <vector >#include <queue> using namespace std; const int maxn = 1000; vector <int> G [maxn]; // int n, root, p [maxn]; void dfs (int u, int fa) in STL, u's father is fa {int d = G [u]. size (); for (int I = 0; I <d; I ++) {const int & v = G [u] [I]; if (v! = Fa) dfs (v, p [v] = u) ;}} int main () {int u, v; scanf ("% d", & n ); for (int I = 0; I <n-1; ++ I) {scanf ("% d", & u, & v); G [u]. push_back (v); G [v]. push_back (u);} scanf ("% d", & root); p [root] =-1; dfs (root,-1); for (int I = 0; I <n; ++ I) printf ("p [% d] = % d \ n", I, p [I]); return 0 ;} /* the output format is p [this node] = this node's father, for example, p [5] = 1; node 5's father is 1; if the node is the root node, the corresponding value is-1 */
Vector_ Baidu Translation
Vector |
[English] incluvekt variance (r) |
[Us] invalid v LIMIT kt limit |
N. |
Vector; heading; [generate] fungal carrier; [Day] vector diameter |
Vt. |
Use a radio to guide... Navigation |
Vector is part of the C ++ standard template library. Chinese characters are occasionally translated as "containers", but they are not accurate. It is a versatile template class and function library that can operate on multiple data structures and algorithms. Vector is considered a container because it can store various types of objects like a container. Simply put, vector is a dynamic array that can store any type, data can be added and compressed.