Xidianoj 1090 Climbing the V8

Source: Internet
Author: User

Title Description

V8 super like to exercise, especially like to climb trees, in order to catch more insects, he hopes that his own from a leaf node to the root node of the longest path, now give you a tree, output V8 required path length.

Input

Multiple sets of data
The first line, a T, represents the number of data groups
For each set of data that follows
The first row is an N, which represents the number of sides.
The next n rows, each line three number u,v,w, indicate that there is a son with V is U, and there is a right side between the W.
1 is the root node.

All data is less than 10000.

Output

The longest path from the root node to a leaf.

--the body difficulty in storing this tree. Tried C's structure, was distracted by free and had to use a vector of water
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cstdlib>#include<vector>using namespaceStd;typedefLong LongLL;structEdgenode {intNext; intweight;}; typedefstructEdgenode Edge;vector<Edge> tree[10001];intDfsintnode) {    intI,sum =0;  for(i=0; I<tree[node].size (); i++) {sum= Max (Sum,dfs (tree[node][i].next) +tree[node][i].weight); }    returnsum;}intMain () {inttime,t,i,j; scanf ("%d",&T);  for(time=1; time<=t;time++){        intN; scanf ("%d",&N);  for(i=1; i<=n;i++) tree[i].clear ();  for(i=1; i<=n;i++){            intu,v,w; scanf (" %d%d%d",&u,&v,&W);            Edge l; L.next= V; L.weight =W;        Tree[u].push_back (l); }        intRoot; printf ("%d\n", DFS (1)); }    return 0; }

Xidianoj 1090 Climbing the V8

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.