/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 46ms 1.938 MiB
#4 Accepted 48ms 1.762 MiB
#5 Accepted 29ms 1.77 MiB
#6 Accepted 38ms 1.801 MiB
#7 Time Exceeded ≥1003ms ≥8.723 MiB
#8 Accepted 959ms 8.52 MiB
#9 Accepted 995ms 8.711 MiB
#10 Accepted 942ms 8.391 MiB
#11 Accepted 932ms 8.719 MiB
#12 Accepted 935ms 8.461 MiB
#13 Accepted 978ms 8.562 MiB
#14 Accepted 285ms 18.418 MiB
#15 Time Exceeded ≥1098ms ≥24.855 MiB

Code


#include <bits/stdc++.h>
using namespace std;
void dfs(int node,vector<vector<int>> &adj,vector<int> &s,vector<int> &light){
    if(light[node] == 1){
            s.push_back(node);
        }
    for(int t : adj[node]){
        dfs(t,adj,s,light);
    }
    
}
void toggle(int node,vector<vector<int>> &adj,vector<int> &light){
    if(light[node] == 1){
            light[node] = 0;
        }else{
            light[node] = 1;
        }
    for(int t : adj[node]){
        
        toggle(t,adj,light);
    }
}
int main()
{
    int n;
    cin >> n;
    vector<int> light(n+1);
    for(int i = 1; i <= n; i++){
        int c;
        cin >> c;
        light[i] = c;
    }
    vector<vector<int>> adj(n+1);
    for(int i = 0; i < n-1; i++){
        int a,b;
        cin >> a >> b;
        adj[a].push_back(b);
    }
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int a,b;
        cin >> a >> b;
        if(a == 2){
            vector<int> s;
            dfs(b,adj,s,light);
            cout << s.size() << endl;
        }else{
            toggle(b,adj,light);
        }
    }
}

Information

Submit By
Type
Submission
Problem
P1101 Mr. Heart and the Enchanted Lights
Contest
Brain Booster #6
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 16:44:44
Judged At
2024-12-17 11:34:07
Judged By
Score
75
Total Time
≥1098ms
Peak Memory
≥24.855 MiB