Submission #6991597


Source Code Expand

Copy
// Gaurav Aggarwal
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
 
ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod;
    } 
    return res%mod; 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 
    // #endif  

    int n;
    int q;
    cin>>n>>q;

    vector<int> graph[n];
    for(int i=0;i<n-1;++i) {
        int a,b;
        cin>>a>>b;
        graph[a-1].pb(b-1);
    }

    int size[n] = {0};

    while(q--) {
        int x,p;
        cin>>x>>p;
        size[x-1] += p;
    }

    queue<int> qq;
    qq.push(0);

    int visited[n] = {0};
    visited[0] = 1;
    while(!qq.empty()) {
        int s = qq.front();
        qq.pop();

        for(int i: graph[s]) {
            if(visited[i] == 0) {
                visited[i] = 1;
                qq.push(i);
                size[i] += size[s];
            }
        }
    }

    debug_arr(size,n);

    return 0;
}

Submission Info

Submission Time
Task D - Ki
User guvi007
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1774 Byte
Status AC
Exec Time 149 ms
Memory 14976 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 2 ms 256 KB
a02 AC 2 ms 256 KB
b03 AC 2 ms 256 KB
b04 AC 147 ms 14720 KB
b05 AC 108 ms 14976 KB
b06 AC 84 ms 9076 KB
b07 AC 81 ms 10100 KB
b08 AC 118 ms 12408 KB
b09 AC 115 ms 11264 KB
b10 AC 149 ms 13184 KB
b11 AC 140 ms 12672 KB
b12 AC 112 ms 12416 KB
b13 AC 149 ms 13184 KB
b14 AC 89 ms 9076 KB