XMash Rush (CC07) - Feedback & Strategies

About popcountll in signed, it just works the same and compiles OK.
https://godbolt.org/z/Q1jvII
https://tech.io/snippet/eoxDhtY
All possible functions leads to the same assembler. Even the int countCasted(long long C), where I use an union{} to reinterpret bits from signed as unsigned. There is 0 penalty on these.

1 Like

I don’t quite understand this code. Why would the id of the neighbors be equal to the incrementing counter?

Not the id, but visited[id].
The BFS starts with visitedFlag++;, which counts the number of BFS runs performed. Then you check, if the visited value equals the current run and set it to that if not. So visited stores, in which BFS run you visited the node for the last time (instead of having a boolean array).

I just noticed the typo in the title (XMash).

1 Like

Oh, I see. This is for running BFS multiple times with the same underlying data set. I get it now. Thank you!