Submission #1593127
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n; vector<int> e[maxn]; long long a[maxn]; bool dfs(int x, int fa) { if(e[x].size() == 1) return true; long long sum = 0, mx = 0; for(auto &it : e[x]) { int v = it; if(v == fa) continue; if(!dfs(v, x)) return false; sum += a[v]; mx = max(mx, a[v]); } mx = min(sum - mx, sum / 2); long long tmp = sum - a[x]; if(tmp < 0 || tmp > mx) return false; a[x] -= tmp; if(x == fa) return a[x] == 0; return true; } int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } for(int i = 1; i < n; i++) { int x, y; scanf("%d%d", &x, &y); e[x].push_back(y); e[y].push_back(x); } if(n == 2) { a[1] == a[2] ? printf("YES\n") : printf("NO\n"); } int pos = -1; for(int i = 1; i <= n; i++) { if(e[i].size() != 1) { pos = i; break; } } dfs(pos, pos) ? printf("YES\n") : printf("NO\n"); }
Submission Info
Submission Time | |
---|---|
Task | C - Cleaning |
User | vjudge1 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 926 Byte |
Status | WA |
Exec Time | 49 ms |
Memory | 13184 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:28:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:30:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld", &a[i]); ^ ./Main.cpp:34:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &x, &y); ^
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 | AC | 46 ms | 6656 KB |
in10.txt | AC | 46 ms | 6656 KB |
in11.txt | AC | 48 ms | 11904 KB |
in12.txt | AC | 49 ms | 11904 KB |
in13.txt | AC | 45 ms | 13184 KB |
in14.txt | AC | 45 ms | 12288 KB |
in15.txt | AC | 2 ms | 2560 KB |
in16.txt | AC | 2 ms | 2560 KB |
in17.txt | WA | 2 ms | 2560 KB |
in18.txt | WA | 2 ms | 2560 KB |
in19.txt | AC | 44 ms | 6656 KB |
in2.txt | AC | 46 ms | 6656 KB |
in20.txt | AC | 43 ms | 6656 KB |
in21.txt | AC | 43 ms | 6656 KB |
in22.txt | AC | 46 ms | 6656 KB |
in23.txt | AC | 45 ms | 6656 KB |
in24.txt | AC | 44 ms | 6656 KB |
in25.txt | AC | 2 ms | 2560 KB |
in26.txt | AC | 44 ms | 6656 KB |
in27.txt | AC | 44 ms | 6656 KB |
in28.txt | AC | 2 ms | 2560 KB |
in29.txt | AC | 41 ms | 6656 KB |
in3.txt | AC | 46 ms | 6656 KB |
in30.txt | AC | 2 ms | 2560 KB |
in31.txt | AC | 45 ms | 6656 KB |
in32.txt | AC | 43 ms | 6656 KB |
in33.txt | AC | 46 ms | 6656 KB |
in34.txt | AC | 46 ms | 6656 KB |
in35.txt | AC | 46 ms | 6656 KB |
in36.txt | AC | 46 ms | 6656 KB |
in37.txt | AC | 2 ms | 2688 KB |
in38.txt | AC | 45 ms | 6656 KB |
in39.txt | AC | 46 ms | 6656 KB |
in4.txt | AC | 46 ms | 6656 KB |
in40.txt | AC | 44 ms | 6656 KB |
in41.txt | AC | 43 ms | 6656 KB |
in42.txt | AC | 46 ms | 6656 KB |
in43.txt | AC | 44 ms | 6656 KB |
in44.txt | AC | 46 ms | 6656 KB |
in45.txt | AC | 46 ms | 6656 KB |
in5.txt | AC | 46 ms | 6656 KB |
in6.txt | AC | 46 ms | 6656 KB |
in7.txt | AC | 41 ms | 6144 KB |
in8.txt | AC | 12 ms | 3584 KB |
in9.txt | AC | 47 ms | 6656 KB |
sample1.txt | AC | 2 ms | 2560 KB |
sample2.txt | AC | 2 ms | 2560 KB |
sample3.txt | AC | 2 ms | 2560 KB |