Submission #1460248
Source Code Expand
#include<bits/stdc++.h> using namespace std; long long N; long long A[100005]; vector<long long> tree[100005]; //上に流れる分 long long dfs(long long pa, long long cur){ //leaf if(tree[cur].size() == 1 && tree[cur][0] == pa){ return A[cur]; } long long child = 0; for(long long i = 0; i < tree[cur].size(); i++){ if(pa == tree[cur][i]){ continue; } long long tmp = dfs(cur, tree[cur][i]); if(tmp < 0){ return -1; } child += tmp; } return (2 * A[cur] - child); } int main(){ cin >> N; for(long long i = 0; i < N; i++){ cin >> A[i]; } for(long long i = 0; i < N - 1; i++){ long long a,b; cin >> a >> b; a--;b--; tree[a].push_back(b); tree[b].push_back(a); } long long ret = dfs(-1, 0); if(ret < 0){ cout << "NO" << endl; return 0; } if(tree[0].size() == 1){ if(A[0] == ret){ cout << "YES" << endl; }else{ cout << "NO" << endl; } }else{ if(0 == ret){ cout << "YES" << endl; return 1; }else{ cout << "NO" << endl; } } }
Submission Info
Submission Time | |
---|---|
Task | C - Cleaning |
User | motomuman |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1073 Byte |
Status | RE |
Exec Time | 117 ms |
Memory | 11776 KB |
Judge Result
Set Name | Sample | All | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 700 | ||||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in4.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | RE | 103 ms | 7168 KB |
in10.txt | AC | 103 ms | 7040 KB |
in11.txt | RE | 112 ms | 10880 KB |
in12.txt | RE | 117 ms | 10880 KB |
in13.txt | RE | 90 ms | 11776 KB |
in14.txt | RE | 91 ms | 11136 KB |
in15.txt | RE | 2 ms | 2560 KB |
in16.txt | AC | 2 ms | 2560 KB |
in17.txt | AC | 2 ms | 2560 KB |
in18.txt | AC | 2 ms | 2560 KB |
in19.txt | RE | 105 ms | 7168 KB |
in2.txt | RE | 103 ms | 7040 KB |
in20.txt | WA | 113 ms | 7040 KB |
in21.txt | RE | 107 ms | 7040 KB |
in22.txt | WA | 103 ms | 7040 KB |
in23.txt | WA | 105 ms | 7168 KB |
in24.txt | AC | 105 ms | 7040 KB |
in25.txt | AC | 2 ms | 2560 KB |
in26.txt | AC | 111 ms | 7168 KB |
in27.txt | AC | 114 ms | 7168 KB |
in28.txt | AC | 2 ms | 2560 KB |
in29.txt | AC | 87 ms | 7040 KB |
in3.txt | RE | 106 ms | 7040 KB |
in30.txt | RE | 2 ms | 2560 KB |
in31.txt | WA | 109 ms | 7040 KB |
in32.txt | RE | 107 ms | 7168 KB |
in33.txt | AC | 105 ms | 7168 KB |
in34.txt | AC | 102 ms | 7168 KB |
in35.txt | AC | 103 ms | 7040 KB |
in36.txt | AC | 104 ms | 7168 KB |
in37.txt | AC | 3 ms | 2688 KB |
in38.txt | AC | 102 ms | 7040 KB |
in39.txt | AC | 102 ms | 7168 KB |
in4.txt | AC | 103 ms | 7168 KB |
in40.txt | AC | 100 ms | 7168 KB |
in41.txt | AC | 102 ms | 7168 KB |
in42.txt | AC | 104 ms | 7040 KB |
in43.txt | AC | 103 ms | 7168 KB |
in44.txt | RE | 103 ms | 7168 KB |
in45.txt | AC | 102 ms | 7168 KB |
in5.txt | AC | 104 ms | 7040 KB |
in6.txt | AC | 105 ms | 7040 KB |
in7.txt | AC | 92 ms | 6656 KB |
in8.txt | AC | 25 ms | 3712 KB |
in9.txt | RE | 103 ms | 7040 KB |
sample1.txt | AC | 2 ms | 2560 KB |
sample2.txt | AC | 2 ms | 2560 KB |
sample3.txt | RE | 2 ms | 2560 KB |