Submission #6993341


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define Max 1000001
#define inf INT_MAX
#define llinf LONG_LONG_MAX
#define rep(i,a,b) for(i=a;i<=b;i++)
#define rrep(i,a,b) for(i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
const ll N=2e5+5,mod=1000000007;
ll val[N]={0};
vector<ll> adj[N],change(N,0);
vector<ll> query[N];
void dfs(ll u,ll p,ll lvl,ll sum)
{
    for(auto q:query[u])
    {
        change[lvl]+=q;
    }
    sum+=change[lvl];
    val[u]=sum;
    for(auto v:adj[u])
    {
        if(v!=p)
        {
            dfs(v,u,lvl+1,sum);
        }
    }
    for(auto q:query[u])
    {
        change[lvl]-=q;
    }
}
signed main()
{
    fast;
    ll pro=1,temp,n,t,i,m,k,j,l,r,mid,x,y,z,rem,carry=0,ind,ans=0,mx=-llinf,mn=llinf,cnt=0,curr=0,prev,sum=0,flag=1,i1=-1,i2=-1;
    cin>>n>>t;
    rep(i,1,n-1)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    while(t--)
    {
        cin>>x>>y;
        query[x].pb(y);
    }
    dfs(1,1,1,0);
    for(i=1;i<=n;i++)
    {
        cout<<val[i]<<' ';
    }
    return 0;
} 

Submission Info

Submission Time
Task D - Ki
User Jaydeep999997
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1413 Byte
Status AC
Exec Time 172 ms
Memory 45952 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 14
Set Name Test Cases
Sample a01, a02
All a01, a02, b03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14
Case Name Status Exec Time Memory
a01 AC 5 ms 12032 KB
a02 AC 5 ms 12032 KB
b03 AC 5 ms 12032 KB
b04 AC 172 ms 45952 KB
b05 AC 148 ms 41588 KB
b06 AC 129 ms 27888 KB
b07 AC 103 ms 24176 KB
b08 AC 157 ms 37364 KB
b09 AC 156 ms 28160 KB
b10 AC 165 ms 40448 KB
b11 AC 165 ms 35456 KB
b12 AC 164 ms 30080 KB
b13 AC 141 ms 39796 KB
b14 AC 129 ms 27760 KB