CF846E.Chemistry in Berland

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment.

Fortunately, chemical laws allow material transformations (yes, chemistry in Berland differs from ours). But the rules of transformation are a bit strange.

Berland chemists are aware of nn materials, numbered in the order they were discovered. Each material can be transformed into some other material (or vice versa). Formally, for each ii (2<=i<=n)(2<=i<=n) there exist two numbers xix_{i} and kik_{i} that denote a possible transformation: kik_{i} kilograms of material xix_{i} can be transformed into 11 kilogram of material ii , and 11 kilogram of material ii can be transformed into 11 kilogram of material xix_{i} . Chemical processing equipment in BerSU allows only such transformation that the amount of resulting material is always an integer number of kilograms.

For each ii ( 1<=i<=n1<=i<=n ) Igor knows that the experiment requires aia_{i} kilograms of material ii , and the laboratory contains bib_{i} kilograms of this material. Is it possible to conduct an experiment after transforming some materials (or none)?

输入格式

The first line contains one integer number nn ( 1<=n<=1051<=n<=10^{5} ) — the number of materials discovered by Berland chemists.

The second line contains nn integer numbers b1,b2... bnb_{1},b_{2}...\ b_{n} ( 1<=bi<=10121<=b_{i}<=10^{12} ) — supplies of BerSU laboratory.

The third line contains nn integer numbers a1,a2... ana_{1},a_{2}...\ a_{n} ( 1<=ai<=10121<=a_{i}<=10^{12} ) — the amounts required for the experiment.

Then n1n-1 lines follow. jj -th of them contains two numbers xj+1x_{j+1} and kj+1k_{j+1} that denote transformation of (j+1)(j+1) -th material ( 1<=xj+1<=j,1<=kj+1<=1091<=x_{j+1}<=j,1<=k_{j+1}<=10^{9} ).

输出格式

Print YES if it is possible to conduct an experiment. Otherwise print NO.

输入输出样例

  • 输入#1

    3
    1 2 3
    3 2 1
    1 1
    1 1
    

    输出#1

    YES
    
  • 输入#2

    3
    3 2 1
    1 2 3
    1 1
    1 2
    

    输出#2

    NO
    
首页