/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 2ms 324.0 KiB
#3 Accepted 48ms 1.785 MiB
#4 Accepted 44ms 1.77 MiB
#5 Accepted 30ms 1.852 MiB
#6 Accepted 38ms 1.801 MiB
#7 Time Exceeded ≥1020ms ≥8.727 MiB
#8 Accepted 958ms 8.488 MiB
#9 Accepted 964ms 8.645 MiB
#10 Accepted 947ms 8.344 MiB
#11 Accepted 984ms 8.727 MiB
#12 Accepted 971ms 8.41 MiB
#13 Accepted 974ms 8.477 MiB
#14 Accepted 294ms 18.359 MiB
#15 Time Exceeded ≥1090ms ≥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-11-11 02:47:40
Judged By
Score
75
Total Time
≥1090ms
Peak Memory
≥24.855 MiB