math-is-stupid's blog

By math-is-stupid, history, 8 years ago, In English

I am trying to solve Problem D Div1 — 233 http://mirror.codeforces.com/contest/398/problem/D. I am getting TLE on testcase 63. Here is my submission http://mirror.codeforces.com/contest/398/submission/21266586. According to me, the time complexity of my code is O[q * (S + K)] where q is number of queries and S (S ~ 500) is constant size defined for a node to be heavy and K denotes total number of heavy nodes. A node is heavy if degree[node] > S. Please correct me if I am wrong. Can I do something better? What changes should I make in my code? Any insights would be really helpful.

  • Vote: I like it
  • 0
  • Vote: I do not like it