Submission #1229387
Source Code Expand
#include<bits/stdc++.h> using namespace std; int N, a[100009], flow[100009]; vector < int > v[100009]; void Ans (bool ok) { if (ok) printf ("YES\n"); else printf ("NO\n"); exit (0); } void dfs (int nod, int tata) { vector < int > h; for (auto it = v[nod].begin (); it != v[nod].end (); it ++) if (*it != tata) dfs (*it, nod), h.push_back (flow[*it]); if (h.empty ()) flow[nod] = a[nod]; else { int s = 0; for (auto it = h.begin (); it != h.end (); it ++) { s += *it; if (s > 2 * a[nod]) Ans (0); } flow[nod] = 2 * a[nod] - s; if (tata == -1 && flow[nod] > 0) Ans (0); h.push_back (flow[nod]); for (auto it = h.begin (); it != h.end (); it ++) if (*it > a[nod]) Ans (0); } } int main () { //freopen ("input", "r", stdin); //freopen ("output", "w", stdout); scanf ("%d", &N); for (int i=1; i<=N; i++) scanf ("%d", &a[i]); if (N == 2) Ans (a[1] == a[2]); for (int i=1; i<N; i++) { int x, y; scanf ("%d %d", &x, &y); v[x].push_back (y); v[y].push_back (x); } int root; for (int i=1; i<=N; i++) if (v[i].size () != 1) root = i; dfs (root, -1); Ans (1); return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Cleaning |
User | geniucos |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1345 Byte |
Status | AC |
Exec Time | 60 ms |
Memory | 13568 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:45:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf ("%d", &N); ^ ./Main.cpp:47:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf ("%d", &a[i]); ^ ./Main.cpp:52:28: 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 | 59 ms | 6656 KB |
in10.txt | AC | 59 ms | 6656 KB |
in11.txt | AC | 59 ms | 12416 KB |
in12.txt | AC | 60 ms | 11776 KB |
in13.txt | AC | 55 ms | 12800 KB |
in14.txt | AC | 57 ms | 13568 KB |
in15.txt | AC | 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 | AC | 49 ms | 6656 KB |
in2.txt | AC | 56 ms | 6656 KB |
in20.txt | AC | 44 ms | 6272 KB |
in21.txt | AC | 44 ms | 6272 KB |
in22.txt | AC | 47 ms | 6656 KB |
in23.txt | AC | 50 ms | 6656 KB |
in24.txt | AC | 47 ms | 6656 KB |
in25.txt | AC | 2 ms | 2560 KB |
in26.txt | AC | 45 ms | 6272 KB |
in27.txt | AC | 45 ms | 6272 KB |
in28.txt | AC | 2 ms | 2560 KB |
in29.txt | AC | 41 ms | 6272 KB |
in3.txt | AC | 54 ms | 6656 KB |
in30.txt | AC | 2 ms | 2560 KB |
in31.txt | AC | 52 ms | 6656 KB |
in32.txt | AC | 46 ms | 6656 KB |
in33.txt | AC | 54 ms | 6656 KB |
in34.txt | AC | 54 ms | 6656 KB |
in35.txt | AC | 49 ms | 6656 KB |
in36.txt | AC | 45 ms | 6656 KB |
in37.txt | AC | 3 ms | 2688 KB |
in38.txt | AC | 54 ms | 6656 KB |
in39.txt | AC | 54 ms | 6656 KB |
in4.txt | AC | 54 ms | 6656 KB |
in40.txt | AC | 54 ms | 6656 KB |
in41.txt | AC | 54 ms | 6656 KB |
in42.txt | AC | 54 ms | 6656 KB |
in43.txt | AC | 49 ms | 6656 KB |
in44.txt | AC | 50 ms | 6656 KB |
in45.txt | AC | 53 ms | 6656 KB |
in5.txt | AC | 53 ms | 6656 KB |
in6.txt | AC | 53 ms | 6656 KB |
in7.txt | AC | 48 ms | 6144 KB |
in8.txt | AC | 14 ms | 3584 KB |
in9.txt | AC | 53 ms | 6656 KB |
sample1.txt | AC | 2 ms | 2560 KB |
sample2.txt | AC | 2 ms | 2560 KB |
sample3.txt | AC | 2 ms | 2560 KB |