uday's blog

By uday, history, 2 months ago, In English

This is a problem I came up with while thinking about cycle-based optimization on graphs. I'm not sure if it's well-known or if I'm missing something obvious, either way I couldn't solve it, so I'd love to hear how more experienced people would approach it.


Problem Statement

You are given a directed graph with N nodes and M edges. It may have self-loops and multiple edges between the same pair of nodes.

Each edge is described by three integers u, v, w:

  • you can move from node u to node v
  • the move takes exactly 1 unit of time
  • you gain w coins after using this edge

You start at node 1 with 0 coins. You may traverse any edge any number of times and revisit nodes freely.

Find the minimum time to collect at least K coins. If it is impossible, print -1.


Examples

Example 1

Input:
5 6 24
1 2 6
2 1 6
1 3 0
3 4 8
4 5 8
5 3 7

Output:
4
Explanation

Example 2

Input:
5 6 31
1 2 6
2 1 6
1 3 0
3 4 8
4 5 8
5 3 7

Output:
5
Explanation

Constraints

$$$1 \le N, M \le 2 \cdot 10^5$$$

$$$1 \le K \le 10^{18}$$$

$$$w \ge 0$$$


Why I Find This Hard

The tricky part is that the best strategy is not fixed, it depends on K:

  • Some cycles have great coins/move ratio but are expensive to reach
  • Others are easy to enter but scale worse
  • K can be up to $$$10^{18}$$$ , so any DP over coins is completely out

My rough instinct says it involves some mix of:

  • SCC condensation: collapsing strongly connected components
  • Cycle profit analysis: finding the highest coins-per-time ratio cycle reachable from node 1
  • Shortest-path reasoning: accounting for the "entry cost" to reach each cycle
  • Binary search on time: fix T, ask if we can collect K coins in T steps

But I can't figure out how to tie these together cleanly, especially when multiple cycles compete and the answer shifts with K.


What I'm Looking For

Would really appreciate insight on any of these:

  • What is the key observation that simplifies this?
  • Is SCC decomposition actually necessary, or is there a cleaner framing?
  • How do you reason about which cycle to "commit to" for a given K?
  • Does this resemble any known classical problem?

Even a rough direction or a pointer to a similar problem would help a lot. Thanks!

Full text and comments »

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

By uday, history, 4 months ago, In English

A year ago when I started using Codeforces, everything just worked for the most part. I could move from problem to problem smoothly, and the judge was there doing its thing in the background. I honestly never thought twice about it.

But lately, things haven't been the same. Every time I try to submit code, I end up staring at a loading screen for minutes on end, or the site's completely unreachable. Even just opening problem statements feels sluggish, and the whole experience has taken a hit.

Today I carved out the whole day to practice. My IDE is open, my solution is ready, but instead of solving problems, I'm basically fighting the server. Don't get me wrong , I love this platform and everything MikeMirzayanov has built here. The community is amazing. But it's kinda frustrating when you're in the zone and then "502 Gateway" for atleast 5-10 mins.

I really hope we get back to the stable Codeforces we all know and love. For now, I guess I'll just keep my solutions saved locally and wait for the website to cooperate.

Full text and comments »

  • Vote: I like it
  • +82
  • Vote: I do not like it

By uday, history, 5 months ago, In English

Hey everyone! I’ve put together a Codeforces Wrapped experience for you all. You can check it out here.

Update: You can now explore your Wrapped history from 2010 up to 2025. Enjoy!

Sharing a few preview screenshots below. Hope you enjoy exploring your year on Codeforces!

Codeforces Wrapped Codeforces Wrapped

Full text and comments »

  • Vote: I like it
  • +612
  • Vote: I do not like it

By uday, history, 7 months ago, In English

Hey all! I am excited to share that we have built some advanced analytics specifically designed for your Codeforces profile. We've been working on this, and I couldn't wait to show you what we've created. It is packed with insights that will help you understand your competitive programming journey better than ever before.

Here are just a few of the many features we've included:

Problem Solving Mastery – This shows how well-equipped you are with different skills and gives you a confidence score compared to your actual rating.

Skill Growth – Track your growth with respect to your rating, implemented using a sophisticated algorithm for calculating these metrics.

Comparing Profiles – Compare your journey, status, win rate, and much more against another competitive programmer. (This feature currently requires authentication, but we'll soon remove that requirement as well.)

And there's much more you'll discover! Check it out here: MyCpTrainer.

Problem Solving Mastery Skill Radar Comparision

Please take it with a grain of salt because we are working hard to fix all the bugs and inconsistencies. I'd love to know what you think and would be happy to implement new metrics based on your suggestions!

Full text and comments »

  • Vote: I like it
  • +160
  • Vote: I do not like it