Memset gives WA!! Ciel and Tomya

Recently i was trying out this question .The question is basically asking us to calculate the number of shortest paths from source to destination in a directed graph.I have used Floyd Warshall method to calculate the number of shortest paths.But during initialising my adjacency matrix and shortest path count matrix(answer matrix),I was using memset which yielded me WA( ). When i replaced the memset with 2 for loop initialisations it gave me AC( Can anyone please explain me this behavior of memset function.

memset can be used only to initialize with values 0 and -1.


@prabhu_3095:Thank you

And for STL containers, we can use fill() for initialization. See here. Hope this helps. :slight_smile:

1 Like

memset sets every 8 bits the value you pass. So for a 32 bit integer, it is filling it like :
00000001000000010000000100000001 : which is not 1
That’s why there is a mistake.
For zero it will work fine and for -1 too (Binary 11111111).

1 Like