/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Wrong Answer 1ms 532.0 KiB
#3 Wrong Answer 16ms 2.977 MiB
#4 Wrong Answer 15ms 3.02 MiB
#5 Accepted 19ms 3.137 MiB
#6 Wrong Answer 24ms 3.066 MiB
#7 Wrong Answer 125ms 18.082 MiB
#8 Wrong Answer 126ms 18.02 MiB
#9 Wrong Answer 128ms 18.02 MiB
#10 Wrong Answer 146ms 18.023 MiB
#11 Wrong Answer 126ms 18.02 MiB
#12 Wrong Answer 127ms 18.02 MiB
#13 Wrong Answer 126ms 18.07 MiB
#14 Time Exceeded ≥1099ms ≥34.02 MiB
#15 Time Exceeded ≥1003ms ≥34.02 MiB
#16 Time Exceeded ≥1101ms ≥34.023 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-10-05 08:50:57
Judged By
Score
10
Total Time
≥1101ms
Peak Memory
≥34.023 MiB