Do I just have to switch over from java? Full code: https://pastebin.com/5HDQ6kRa
The logic should be correct but it's TLEing for some cases, and I'm pretty sure I have the optimal logic, but it's either cuz Java is slow or something w/ the implementation of the code
I'm lazy to look at the code, even java, but you should solve this problem with graph coloring, it's classical. You should use 2 color and color this graph so that no adjacent vertices have the same color. Some time ago I got accepted in this problem with graph coloring.
yeah that's my logic too but it's TLEing randomly cuz its like borderline 1s for each case
https://imgur.com/yjFP8W3 https://imgur.com/ezWXkYC
prefer to use the iterative approach for cses problems. AC code in java https://ideone.com/K32kmB
i also BFSed it but it TLEd as well, perhaps implementation is bad https://pastebin.com/dcVmMdeY
wait wth. i tried to implements parts of your code and your scanner was the determining factor, wth? bro ur scanner is insane, so Integer.parseInt() is slower than your just normal parser?
yes, this template is fast enough to be used in cses.
Auto comment: topic has been updated by bobbilyking (previous revision, new revision, compare).