bijju74's blog

By bijju74, history, 6 weeks ago, In English

So basically I have a vector<array<long long, 2>> adj[N]; and I want to access it's elements for(int i=0; i<n; ++i){ long long X=i;

long long Y=adj[i][1]; //gives error
    long long W=adj[i][0]; //gives error

}

error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 2> >, std::array<int, 2> >::value_type' {aka 'std::array<int, 2>'} to 'int' in initialization

I've been trying to solve what's wrong with this & why this isn't possible. Can someone help please?

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by bijju74 (previous revision, new revision, compare).

»
6 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

Hello! For your declaration, change vector<array<long long, 2>> adj[N]; to vector<array<long long, 2>> adj(N);. Just replace the rectangular brackets with circular brackets.

Hope that helps! :)