Submission #1092457
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef pair<int, int> pi; lint n, a[100005], b[100005], sum; vector<int> gph[100005]; lint dfs(int x, int p){ lint sum = 0; for(auto &i : gph[x]){ if(i != p) sum += dfs(i, x); } if(sum == 0) return a[x]; lint death = sum - a[x]; lint alive = a[x] - death; if(death < 0 || alive < 0){ puts("NO"); exit(0); } return alive; } int main(){ scanf("%lld",&n); for(int i=1; i<=n; i++){ scanf("%lld",&a[i]); } for(int i=0; i<n-1; i++){ int s, e; scanf("%d %d",&s,&e); gph[s].push_back(e); gph[e].push_back(s); } if(n == 2){ puts(a[1] == a[2] ? "YES" : "NO"); return 0; } for(int i=1; i<=n; i++){ if(gph[i].size() > 1){ if(dfs(i, -1) != 0){ puts("NO"); return 0; } puts("YES"); return 0; } } }
Submission Info
Submission Time | |
---|---|
Task | C - Cleaning |
User | koosaga |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 869 Byte |
Status | WA |
Exec Time | 56 ms |
Memory | 11776 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:25:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld",&n); ^ ./Main.cpp:27:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld",&a[i]); ^ ./Main.cpp:31:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d",&s,&e); ^
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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 51 ms | 6656 KB |
in10.txt | AC | 51 ms | 6656 KB |
in11.txt | AC | 55 ms | 10880 KB |
in12.txt | AC | 56 ms | 10880 KB |
in13.txt | AC | 53 ms | 11776 KB |
in14.txt | AC | 53 ms | 11136 KB |
in15.txt | AC | 5 ms | 2560 KB |
in16.txt | AC | 5 ms | 2560 KB |
in17.txt | AC | 5 ms | 2560 KB |
in18.txt | AC | 5 ms | 2560 KB |
in19.txt | WA | 51 ms | 6656 KB |
in2.txt | AC | 51 ms | 6656 KB |
in20.txt | WA | 51 ms | 6656 KB |
in21.txt | WA | 51 ms | 6656 KB |
in22.txt | WA | 51 ms | 6656 KB |
in23.txt | AC | 49 ms | 6656 KB |
in24.txt | AC | 49 ms | 6656 KB |
in25.txt | AC | 5 ms | 2560 KB |
in26.txt | AC | 50 ms | 6656 KB |
in27.txt | AC | 50 ms | 6656 KB |
in28.txt | AC | 5 ms | 2560 KB |
in29.txt | AC | 46 ms | 6656 KB |
in3.txt | AC | 50 ms | 6656 KB |
in30.txt | AC | 5 ms | 2560 KB |
in31.txt | AC | 50 ms | 6656 KB |
in32.txt | AC | 49 ms | 6656 KB |
in33.txt | AC | 51 ms | 6656 KB |
in34.txt | AC | 51 ms | 6656 KB |
in35.txt | AC | 50 ms | 6656 KB |
in36.txt | AC | 51 ms | 6656 KB |
in37.txt | AC | 5 ms | 2688 KB |
in38.txt | AC | 50 ms | 6656 KB |
in39.txt | AC | 50 ms | 6656 KB |
in4.txt | AC | 51 ms | 6656 KB |
in40.txt | AC | 48 ms | 6656 KB |
in41.txt | AC | 49 ms | 6656 KB |
in42.txt | AC | 51 ms | 6656 KB |
in43.txt | AC | 49 ms | 6656 KB |
in44.txt | WA | 51 ms | 6656 KB |
in45.txt | AC | 51 ms | 6656 KB |
in5.txt | AC | 51 ms | 6656 KB |
in6.txt | AC | 51 ms | 6656 KB |
in7.txt | AC | 46 ms | 6144 KB |
in8.txt | AC | 15 ms | 3584 KB |
in9.txt | AC | 51 ms | 6656 KB |
sample1.txt | AC | 5 ms | 2560 KB |
sample2.txt | AC | 5 ms | 2560 KB |
sample3.txt | AC | 5 ms | 2560 KB |