bobbilyking's blog

By bobbilyking, history, 6 years ago, In English

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

  • Vote: I like it
  • -15
  • Vote: I do not like it

»
6 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

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.

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

prefer to use the iterative approach for cses problems. AC code in java https://ideone.com/K32kmB

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

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