Submission #1092719


Source Code Expand

Copy
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

void bad() {
	puts("NO");
	exit(0);
}
void good() {
	puts("YES");
	exit(0);
}

const int MAXN = 100000 + 20;
int A[MAXN];
VI e[MAXN];

int DFS(int x, int p) {
	if(SZ(e[x]) == 1) {
		return A[x];
	}
	int sum = 0, big = 0;
	for(int u : e[x]) {
		if(u == p) continue;
		int r = DFS(u, x);
		sum += r;
		big = max(big, r);
	}
	if(sum < A[x]) bad();
	if(A[x] * 2 < sum) bad();
	int fold = sum - A[x];
	if(sum - big < fold) bad();
	debug("x = %d, fold = %d\n", x, fold);
	return sum - 2 * fold;
}

int main() {
	int N;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++)
		scanf("%d", &A[i]);
	for(int i = 1; i < N; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		e[a].PB(b);
		e[b].PB(a);
	}
	if(N == 2) {
		if(A[1] == A[2]) good();
		else bad();
	}
	for(int i = 1; i <= N; i++)
		if(SZ(e[i]) > 1) {
			if(DFS(i, 0) == 0) good();
			else bad();
		}
	return 0;
}

Submission Info

Submission Time
Task C - Cleaning
User t1016d
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1281 Byte
Status
Exec Time 63 ms
Memory 12928 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:52:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
./Main.cpp:54:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &A[i]);
                     ^
./Main.cpp:57:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
                        ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample1.txt, sample2.txt, sample3.txt
All 700 / 700 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 52 ms 6272 KB
in10.txt 52 ms 6144 KB
in11.txt 60 ms 11520 KB
in12.txt 63 ms 11520 KB
in13.txt 59 ms 12928 KB
in14.txt 59 ms 11904 KB
in15.txt 5 ms 2560 KB
in16.txt 5 ms 2560 KB
in17.txt 5 ms 2560 KB
in18.txt 5 ms 2560 KB
in19.txt 53 ms 6272 KB
in2.txt 55 ms 6272 KB
in20.txt 50 ms 6144 KB
in21.txt 50 ms 6144 KB
in22.txt 52 ms 6144 KB
in23.txt 52 ms 6272 KB
in24.txt 52 ms 6144 KB
in25.txt 5 ms 2560 KB
in26.txt 52 ms 6144 KB
in27.txt 53 ms 6272 KB
in28.txt 5 ms 2560 KB
in29.txt 49 ms 6272 KB
in3.txt 52 ms 6272 KB
in30.txt 5 ms 2560 KB
in31.txt 53 ms 6144 KB
in32.txt 52 ms 6144 KB
in33.txt 53 ms 6272 KB
in34.txt 54 ms 6272 KB
in35.txt 53 ms 6144 KB
in36.txt 55 ms 6272 KB
in37.txt 5 ms 2560 KB
in38.txt 53 ms 6272 KB
in39.txt 58 ms 6272 KB
in4.txt 54 ms 6272 KB
in40.txt 51 ms 6272 KB
in41.txt 52 ms 6144 KB
in42.txt 53 ms 6144 KB
in43.txt 54 ms 6272 KB
in44.txt 53 ms 6144 KB
in45.txt 55 ms 6272 KB
in5.txt 54 ms 6272 KB
in6.txt 56 ms 6272 KB
in7.txt 48 ms 5760 KB
in8.txt 16 ms 3584 KB
in9.txt 54 ms 6272 KB
sample1.txt 5 ms 2560 KB
sample2.txt 5 ms 2560 KB
sample3.txt 5 ms 2560 KB