Why are the methods Vector.empty() and Vector.size() == 0 not working. I get the following error- Probably, the solution is executed with error 'not valid value for bool' on the line 34. Here are the submission links - 1. https://codeforces.net/contest/744/submission/90258791 2. https://codeforces.net/contest/744/submission/90257488 Please help!
Replace bool[] arrays with vector
I believe the error is thrown by the "isGov" array, in which you have possibly not assigned values to all elements, but later attempt to access all of them. But since in arrays, the initial value is random, it is not recognized as a boolean value and causes an error.
I would suggest either using a vector or setting all values to false initially.
In which order is this evaluated?
if (v[i].size() == 0 && !isGov[i])
The problem is not that, I think using vector instead of bool [] will work, or you can use memset and initialize all values of isGov as false at the beginning.
In your code isGov is uninitialized
should be replaced with
You should use a vector though as others have suggested.
Does the latter guarantee that everything is 0? Same of an array of ints?
Yes, the latter guarantees everything is zero. This feature for VLAs is a G++ extension, however. (variable-length arrays in C++ are also a G++ extension). For non-VLAs, array brace initialization is part of C++. (Variable-length arrays are arrays with a dynamic size)