bobbilyking's blog

By bobbilyking, history, 15 months 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

»
15 months ago, # |
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.

»
15 months ago, # |
  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

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    i also BFSed it but it TLEd as well, perhaps implementation is bad https://pastebin.com/dcVmMdeY

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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?

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      yes, this template is fast enough to be used in cses.

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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