# UVa 548-tree

Source: Internet
Author: User

Title: Give you a tree in the root sequence and the posterior root sequence traversal, the path from the root to the leaves of the number and the smallest.

Analysis: DS, tree, recursive. The direct recursive solution is updated with global variables.

Description: If the path is the same as the same, the output of the lowest leaf value.

`#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace std;int p[10001];int i[10001];int min,leaf;void dfs (int il, int ir, int pl , int PR, int value) {int f = il,l,r;while (i[f]! = P[PR]) + + f;if (f > IL) dfs (IL, f-1, pl, pl+f-il-1, VALUE+P[PR]); if (f < IR) DFS (f+1, IR, Pl+f-il, Pr-1, VALUE+P[PR]); if (pl = = pr) {if (min > P[pl]+value) {min = P[pl]+value; Leaf = P[pl];} else if (Min = = P[pl]+value && leaf > p[pl]) Leaf = P[PL];}} int main () {char ch;while (~scanf ("%d", &i[0]) {int count = 1;while (GetChar ()! = ' \ n ') scanf ("%d", &i[count + +]); fo R (int i = 0; i < count; + + i) scanf ("%d%c", &p[i],&ch); Min = 100000001; leaf = -1;dfs (0, count-1, 0, count-1, 0);p rintf ("%d\n", leaf);}    return 0;}`

UVa 548-tree

Related Keywords:

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.