When I write a two-dimensional array in AtCoder, I cannot determine the cause of RE (execution time error) in some problems.

Asked 1 years ago, Updated 1 years ago, 238 views

Heap-buffer-overflow occurs when trying to implement adjacency lists
This is a continuation of the problem I asked you about on this link, but I have not been able to determine the cause of the RE (runtime error) in some cases in this problem.
I would appreciate it if you could let me know if anyone understands.
[Additional note]
As for one case and the case mentioned in the above sentence, the test case is not published in AtCoder, so I don't know for myself.
Thank you for pointing it out.

#include<bits/stdc++.h>

using namespace std;

void solve() {
    uint64_tN,Q;
    cin>>N>Q;
    vector<vector<uint64_t>>G(N+1);
    for(uint64_ti=0;i<Q;i++){
        uint64_t T, A, B;
        cin>>T>>A>>B;
        if(T==1){
            auto itr = find(G[A].begin(), G[A].end(), B);
            if(itr==G[A].end()){
                G[A].push_back(B);
            }
        }
        if(T==2){
            auto itr = find(G[A].begin(), G[A].end(), B);
            if(itr!=G[A].end()){
                G[A].erase(itr);
            }
        }
        if(T==3){
            bool AhaveB = false;
            for(uint64_tA_friend:G[A]){
                if(A_friend==B){
                    AhaveB = true;
                }
            }
            bool BhaveA = false;
            for(uint64_tB_friend:G[B]){
                if(B_friend==A){
                    BaveA = true;
                }
            }
            if(AhaveB&&BhaveA){
                cout<<"Yes"<<endl;
            } else{
                cout<<"No"<<endl;
            }
        }
    }
}

int main() {
    solve();
}

I made the changes as above.
The following are the issues:
https://atcoder.jp/contests/abc278/tasks/abc278_c

c++

2022-11-21 13:22

1 Answers

Questions will be asked

2 NN 10109

9

said he.

vector<vector<uint64_t>>G(N+1);

uint64_t is 8 bytes, so G will consume 109x8=8GB.Does this exceed the memory limit?

9


2022-11-21 19:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.