/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Wrong Answer 1ms 532.0 KiB
#3 Wrong Answer 19ms 3.047 MiB

Code

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define endl '\n'
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
#define all(v) v.begin(), v.end()
#define pb push_back //
#define mp make_pair
#define fi first                         //
#define se second                        //
#define yes cout << "YES" << endl        //
#define no cout << "NO" << endl          //
#define M 1000000007                     // 1e9+7
#define gcd(a, b) __gcd(a, b)            //
#define lcm(a, b) a *b / gcd(a, b)       //
#define memz(a) memset(a, 0, sizeof(a))  //
#define memn(a) memset(a, -1, sizeof(a)) //
ll dfs(ll par,ll node,ll light[],ll val[],vector<ll>graph[],ll parent[])
{
    val[node]=0;
    parent[node]=par;
    for(auto child:graph[node])
    {
        if(child!=par)val[node]+=dfs(node,child,light,val,graph,parent);
    }
    val[node]+=light[node];
    return val[node];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll light[n+1];
    for(int i=1;i<=n;i++)cin>>light[i];
    ll val[n+1];
    vector<ll>graph[n+1];
    for(int i=1;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    ll parent[n+1];
    dfs(0,1,light,val,graph,parent);
    ll q;
    cin>>q;
    while(q--)
    {
        ll c,p;
        cin>>c>>p;
        if(c==2)cout<<val[p]<<endl;
        else
        {
            ll cng;
            if(light[p]==0)cng=1;
            else cng=-1;
            while(p!=0)
            {
                val[p]+=cng;
                p=parent[p];
            }
        }
    }

}

Information

Submit By
Type
Submission
Problem
P1101 Mr. Heart and the Enchanted Lights
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-05 08:50:57
Judged At
2024-11-11 02:40:15
Judged By
Score
5
Total Time
19ms
Peak Memory
3.047 MiB