Submission #1655888
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int Maxn = 111111; struct Edge { int v, id; Edge *nxt; } pool[Maxn*2], *tree[Maxn], *tail = pool; inline void addedge(const int &u, const int &v, const int &id) { tail->v = v, tail->id = id; tail->nxt = tree[u], tree[u] = tail++; } int n, a[Maxn], w[Maxn]; bool isleaf[Maxn]; void dfs(int u, int fa, int lastid) { w[lastid] = a[u]; isleaf[u] = true; for (Edge *p = tree[u]; p; p = p->nxt) { if (p->v != fa) { isleaf[u] = false; dfs(p->v, u, p->id); w[lastid] -= w[p->id]; } } if (!isleaf[u]) { w[lastid] += a[u]; } } void solve() { if (n == 2) { if (a[1] == a[2]) { puts("YES"); } else { puts("NO"); } return; } for (int i = 1, cnum; i <= n; ++i) { cnum = 0; for (Edge *p = tree[i]; p; p = p->nxt) { ++cnum; } if (cnum > 1) { dfs(i, 0, 0); break; } } if (w[0] != 0) { puts("NO"); return; } for (int i = 1; i < n; ++i) { if (w[i] < 0) { puts("NO"); return; } } for (int i = 1; i <= n; ++i) { if (!isleaf[i]) { LL tot = 0; for (Edge *p = tree[i]; p; p = p->nxt) { tot += w[p->id]; } for (Edge *p = tree[i]; p; p = p->nxt) { if (w[p->id] > tot/2) { puts("NO"); return; } } } } puts("YES"); } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i){ scanf("%d", &a[i]); } for (int i = 1, x, y; i < n; ++i) { scanf("%d%d", &x, &y); addedge(x, y, i), addedge(y, x, i); } solve(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Cleaning |
User | vjudge5 |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1503 Byte |
Status | AC |
Exec Time | 39 ms |
Memory | 9088 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:79:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:81:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &a[i]); ^ ./Main.cpp:84: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 | 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 | 39 ms | 5628 KB |
in10.txt | AC | 35 ms | 4992 KB |
in11.txt | AC | 37 ms | 8320 KB |
in12.txt | AC | 37 ms | 8320 KB |
in13.txt | AC | 33 ms | 9088 KB |
in14.txt | AC | 33 ms | 8448 KB |
in15.txt | AC | 1 ms | 256 KB |
in16.txt | AC | 1 ms | 256 KB |
in17.txt | AC | 1 ms | 256 KB |
in18.txt | AC | 1 ms | 256 KB |
in19.txt | AC | 36 ms | 4992 KB |
in2.txt | AC | 35 ms | 4992 KB |
in20.txt | AC | 33 ms | 4992 KB |
in21.txt | AC | 33 ms | 4992 KB |
in22.txt | AC | 34 ms | 4992 KB |
in23.txt | AC | 35 ms | 4992 KB |
in24.txt | AC | 33 ms | 4992 KB |
in25.txt | AC | 1 ms | 256 KB |
in26.txt | AC | 34 ms | 4992 KB |
in27.txt | AC | 36 ms | 4992 KB |
in28.txt | AC | 1 ms | 256 KB |
in29.txt | AC | 32 ms | 4992 KB |
in3.txt | AC | 35 ms | 4992 KB |
in30.txt | AC | 1 ms | 256 KB |
in31.txt | AC | 33 ms | 4992 KB |
in32.txt | AC | 33 ms | 4992 KB |
in33.txt | AC | 35 ms | 4992 KB |
in34.txt | AC | 35 ms | 4992 KB |
in35.txt | AC | 33 ms | 4992 KB |
in36.txt | AC | 33 ms | 4992 KB |
in37.txt | AC | 2 ms | 256 KB |
in38.txt | AC | 33 ms | 4992 KB |
in39.txt | AC | 33 ms | 4992 KB |
in4.txt | AC | 35 ms | 4992 KB |
in40.txt | AC | 33 ms | 4992 KB |
in41.txt | AC | 33 ms | 4992 KB |
in42.txt | AC | 32 ms | 4992 KB |
in43.txt | AC | 34 ms | 4992 KB |
in44.txt | AC | 34 ms | 4992 KB |
in45.txt | AC | 33 ms | 4992 KB |
in5.txt | AC | 35 ms | 4992 KB |
in6.txt | AC | 35 ms | 4992 KB |
in7.txt | AC | 31 ms | 4480 KB |
in8.txt | AC | 9 ms | 2944 KB |
in9.txt | AC | 35 ms | 4992 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |