Submission #1693507
Source Code Expand
#include <algorithm> #include <cstdio> const int N=100005; int fst[N],deg[N],a[N],tot=0; struct Edge{ int to,nxt; }e[N*2]; void addedge(int x,int y){ e[++tot].to=y;e[tot].nxt=fst[x];fst[x]=tot;deg[y]++; } bool dfs(int x,int father){ if (deg[x]==1){ return 1; } int sum=0,mx=0; for (int i=fst[x];i;i=e[i].nxt){ int y=e[i].to; if (y!=father){ if (!dfs(y,x)) return 0; sum+=a[y]; mx=std::max(mx,a[y]); } } a[x]=a[x]*2-sum; return (a[x]>=0 && mx*2-sum<=a[x] && a[x]<=sum); } int main(){ int n,root=0; scanf("%d\n",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]); for (int i=1;i<n;i++){ int x,y; scanf("%d%d",&x,&y); addedge(x,y); addedge(y,x); } if (n==2){ printf(a[1]==a[2]?"YES":"NO"); return 0; } for (int i=1;i<=n;i++) if (deg[i]>1) root=i; if (dfs(root,0) && !a[root]) printf("YES\n"); else printf("NO\n"); }
Submission Info
Submission Time | |
---|---|
Task | C - Cleaning |
User | aufeas |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 916 Byte |
Status | AC |
Exec Time | 35 ms |
Memory | 9984 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:35:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d\n",&n); ^ ./Main.cpp:36:42: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] for (int i=1;i<=n;i++) scanf("%d",&a[i]); ^ ./Main.cpp:39:22: 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 | 700 / 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 | 32 ms | 2944 KB |
in10.txt | AC | 31 ms | 2944 KB |
in11.txt | AC | 35 ms | 8832 KB |
in12.txt | AC | 35 ms | 8192 KB |
in13.txt | AC | 31 ms | 9216 KB |
in14.txt | AC | 32 ms | 9984 KB |
in15.txt | AC | 0 ms | 128 KB |
in16.txt | AC | 1 ms | 128 KB |
in17.txt | AC | 1 ms | 128 KB |
in18.txt | AC | 1 ms | 128 KB |
in19.txt | AC | 30 ms | 2944 KB |
in2.txt | AC | 31 ms | 2944 KB |
in20.txt | AC | 29 ms | 2944 KB |
in21.txt | AC | 28 ms | 2944 KB |
in22.txt | AC | 30 ms | 2944 KB |
in23.txt | AC | 29 ms | 2944 KB |
in24.txt | AC | 30 ms | 2944 KB |
in25.txt | AC | 0 ms | 128 KB |
in26.txt | AC | 30 ms | 2944 KB |
in27.txt | AC | 30 ms | 2944 KB |
in28.txt | AC | 1 ms | 128 KB |
in29.txt | AC | 26 ms | 2944 KB |
in3.txt | AC | 31 ms | 2944 KB |
in30.txt | AC | 0 ms | 128 KB |
in31.txt | AC | 29 ms | 2944 KB |
in32.txt | AC | 31 ms | 2944 KB |
in33.txt | AC | 31 ms | 2944 KB |
in34.txt | AC | 31 ms | 2944 KB |
in35.txt | AC | 29 ms | 2944 KB |
in36.txt | AC | 31 ms | 2944 KB |
in37.txt | AC | 1 ms | 256 KB |
in38.txt | AC | 31 ms | 2944 KB |
in39.txt | AC | 31 ms | 2944 KB |
in4.txt | AC | 31 ms | 2944 KB |
in40.txt | AC | 32 ms | 2944 KB |
in41.txt | AC | 32 ms | 2944 KB |
in42.txt | AC | 31 ms | 2944 KB |
in43.txt | AC | 29 ms | 2944 KB |
in44.txt | AC | 29 ms | 2944 KB |
in45.txt | AC | 31 ms | 2944 KB |
in5.txt | AC | 31 ms | 2944 KB |
in6.txt | AC | 31 ms | 2944 KB |
in7.txt | AC | 28 ms | 2560 KB |
in8.txt | AC | 8 ms | 768 KB |
in9.txt | AC | 31 ms | 2944 KB |
sample1.txt | AC | 1 ms | 128 KB |
sample2.txt | AC | 1 ms | 128 KB |
sample3.txt | AC | 0 ms | 128 KB |