Submission #1556066


Source Code Expand

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e5+10;
using namespace std;
inline ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
inline ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
inline void umax(ll &p,ll q){if(p<q)p=q;}
inline void umin(ll &p,ll q){if(p>q)p=q;}
inline ll read()
{
    ll x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,k,t,a[maxn];
ll cnt[maxn];
vi e[maxn];
bool flag=true;
void dfs(int x,int y)
{
    if(!flag)return;
    ll p=0;
    for(int z:e[x])
    {
        if(z==y)continue;
        dfs(z,x);
        if(cnt[z]>a[x])
        {
            flag=false;
            return;
        }
        p+=cnt[z];
    }
    if((int)e[x].size()==1)
    {
        cnt[x]=a[x];
    }
    else
    {
        cnt[x]=(ll)2*a[x]-p;
        if(cnt[x]<0||cnt[x]>a[x])
        {
            flag=false;
            return;
        }
    }
}
int main()
{
    int i,j;
    scanf("%d",&n);
    rep(i,1,n)scanf("%d",&a[i]);
    rep(i,1,n-1)scanf("%d%d",&j,&k),e[j].pb(k),e[k].pb(j);
    if(n==2)
    {
        puts(a[1]==a[2]?"YES":"NO");
        return 0;
    }
    rep(i,1,n)
    {
        if((int)e[i].size()>1)
        {
            dfs(i,-1);
            if(!flag)puts("NO");
            else if(cnt[i]!=0)puts("NO");
            else puts("YES");
            return 0;
        }
    }
    return 0;
}

Submission Info

Submission Time
Task C - Cleaning
User vjudge5
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1954 Byte
Status AC
Exec Time 49 ms
Memory 13568 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:76:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
./Main.cpp:77:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     rep(i,1,n)scanf("%d",&a[i]);
                                ^
./Main.cpp:78:58: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     rep(i,1,n-1)scanf("%d%d",&j,&k),e[j].pb(k),e[k].pb(j);
                                                          ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 51
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 48 ms 7040 KB
in10.txt AC 48 ms 7040 KB
in11.txt AC 49 ms 12288 KB
in12.txt AC 49 ms 12288 KB
in13.txt AC 46 ms 13568 KB
in14.txt AC 45 ms 12672 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 45 ms 7040 KB
in2.txt AC 47 ms 7040 KB
in20.txt AC 43 ms 6272 KB
in21.txt AC 43 ms 6272 KB
in22.txt AC 46 ms 7040 KB
in23.txt AC 45 ms 7040 KB
in24.txt AC 44 ms 7040 KB
in25.txt AC 2 ms 2560 KB
in26.txt AC 45 ms 6272 KB
in27.txt AC 44 ms 6272 KB
in28.txt AC 2 ms 2560 KB
in29.txt AC 41 ms 6272 KB
in3.txt AC 47 ms 7040 KB
in30.txt AC 2 ms 2560 KB
in31.txt AC 46 ms 7040 KB
in32.txt AC 44 ms 7040 KB
in33.txt AC 47 ms 7040 KB
in34.txt AC 48 ms 7040 KB
in35.txt AC 47 ms 7040 KB
in36.txt AC 47 ms 7040 KB
in37.txt AC 2 ms 2688 KB
in38.txt AC 46 ms 7040 KB
in39.txt AC 46 ms 7040 KB
in4.txt AC 47 ms 7040 KB
in40.txt AC 44 ms 7040 KB
in41.txt AC 44 ms 7040 KB
in42.txt AC 47 ms 7040 KB
in43.txt AC 45 ms 7040 KB
in44.txt AC 47 ms 7040 KB
in45.txt AC 47 ms 7040 KB
in5.txt AC 47 ms 7040 KB
in6.txt AC 48 ms 7040 KB
in7.txt AC 42 ms 6528 KB
in8.txt AC 12 ms 3584 KB
in9.txt AC 47 ms 7040 KB
sample1.txt AC 2 ms 2560 KB
sample2.txt AC 2 ms 2560 KB
sample3.txt AC 2 ms 2560 KB