[Luogu U8984] [New boundless summer Open] frozen watermelon [tree-shaped array]

Source: Internet
Author: User

Topic Background

Midsummer, Ice goblin Qi Cirno found a large area of watermelon, finally can eat delicious frozen watermelon.

Title Description

Qi Cirno is the ability to manipulate the level of the Goblin, one day she found a piece of watermelon land. Here are n watermelon, by n-1 watermelon Vine connected, forming a root tree, Qi Cirno want to freeze them up slowly eat.

These watermelon vines have a magical nature, can be through the cold degree of its air-conditioning to enlarge or reduce, each watermelon to enlarge/reduce the cold degree of cooling ability value of WI, indicating that after the air conditioning after it, the cold degree value of X will become X*WI. Each watermelon also has a cold value, on a hot summer day, all the watermelon's cold value is initially 0.

Kiki will make two moves:

①. To the watermelon I release the cold degree of x air-conditioning. This air-conditioning along the watermelon vine to the "watermelon tree" leaf nodes spread, the cold degree of cooling will follow the above rules change. When you encounter a watermelon with multiple watermelon vines, each leaf node in the direction of the watermelon will get the same cold as the original air-conditioning. The cold degree value of all watermelon in the pathway is added to the cold degree value of the cooling.

⑨. Ask you what the cold value of watermelon I is.

Wait, why do you have ⑨? Because the idiot Gigi will forget how much ice she put.

So, to help her calculate the task is to you.

input/output format

Input format:

The first line is an integer n, which indicates the number of watermelons.

The watermelon number is 1~n,1 for the root of this "watermelon tree".

Next n-1 line, each line has two integer u,v and a real w, indicating that watermelon U and Watermelon V is connected with a vine, which enlarges/reduces the cold level of the cooling capacity value is W.

The next line is an integer m, which represents the number of operations.

Next m lines, two or three integers per line.

The first number can only be 1 or 9.

If it is 1, then an integer I and a real number x indicate that the cold air is released to the watermelon I with a cool degree of x.

If it is 9, the next integer i, indicates the cold degree value of the watermelon that is asking for the number I.

Output format:

For each operation ⑨, the output line is a real number, indicating the cold degree value of the corresponding watermelon.

input/Output sampleInput Sample # #:
41 2 1.000000002 3 0.000000003 4 1.0000010191 1 3.000000009 29 31 2 1.428560319 49 21 3 4.233333339 29 4
Sample # # of output:
3.000000000.000000000.000000004.428560314.428560314.23333761
Description

Sub-tasks may have the following special properties:

"Watermelon Tree" degenerated into a chain

The real numbers in the input data are reserved for 8 decimal places, and the contestants ' answers are judged correctly and only if the output and the standard answer error do not exceed 10^-7. Pay particular attention to the problem of floating point accuracy.

In the actual data, the cold degree of the air-conditioning x range is [ -0.1,0.1]

(The range of cold-air cooling in the sample is [1,5])

20 cent code

n<=1000 m<=1000

Nice little tree.

---> Simple, full-test instructions traversal tree algorithm

1#include <cstdio>2#include <cstring>3#include <iostream>4#include <vector>5#include <cmath>6 using namespacestd;7 8InlineintRead () {9     intRe=0;Ten     Charch; One     BOOLflag=0; A      while((Ch=getchar ())! ='-'&& (ch<'0'|| Ch>'9')); -ch=='-'? flag=1: re=ch-'0'; -      while((Ch=getchar ()) >='0'&&ch<='9') re= (re<<1) + (re<<3) +ch-'0'; the     returnflag?-Re:re; - } -  -typedefLong Doublelb; +  - structedge{ +     intTo,next; A lb W; atEdgeintto=0,intnext=0, LB w=0): - to, Next (next), W (w) {} - }; -  - Const intmaxn=100001; -  in ConstLB eps=1e-8; -Vector<edge>edges; toVector<edge>Tree; + intn,m,cnt,root=1; - intHEAD[MAXN],TMP_HEAD[MAXN]; the lb DATA[MAXN]; *  $ BOOLoo (lb ww) {Panax Notoginseng     if(Fabs (WW) <eps)return 0; -     return 1; the } +  AInlinevoidAdd_edge (int  from,intto,lb W) { theEdges.push_back (Edge (to,head[ from],w)); +head[ from]=++CNT; -Edges.push_back (Edge ( from, Head[to],w)); $head[to]=++CNT; $ } -  -InlinevoidAdd_tree (int  from,intto,lb W) { theTree.push_back (Edge (to,tmp_head[ from],w)); -tmp_head[ from]=++CNT;Wuyi } the  - voidDfs_tree (intXintFA) { Wu      for(intEe=head[x];ee;ee=edges[ee].next) -         if(edges[ee].to!=FA) { About Add_tree (X,EDGES[EE].TO,EDGES[EE].W); $ Dfs_tree (edges[ee].to,x); -         } - } -  A voidDfsintss,lb ww) { +data[ss]+=ww; the      for(intEe=head[ss];ee;ee=tree[ee].next) -         if(oo (TREE[EE].W)) $DFS (tree[ee].to,ww*TREE[EE].W); the } the  the intMain () { the     //freopen ("temp.in", "R", stdin); -Cnt=0; inn=read (); theEdges.push_back (Edge (0,0,0)); the      for(intI=1; i<n;i++){ About         int  from=read (), to=read (); theLB w;scanf ("%LF",&W); theAdd_edge ( from, to,w); the     } +Cnt=0; -Tree.push_back (Edge (0,0,0)); theDfs_tree (Root,0);Bayi swap (head,tmp_head); them=read (); the      for(intI=0; i<m;i++){ -         intOp=read (), ss=read (); -         if(op&8){ theprintf"%.8lf\n", Data[ss]); the         } the         Else{ theLB ww;scanf ("%LF",&ww); - DFS (SS,WW); the         } the     } the     return 0;94}

100 cent Code

...

A tree-like array on the label but I won't, QwQ.

After two days , we'll put it out.

[Luogu U8984] [New boundless summer Open] frozen watermelon [tree-shaped array]

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.