Glimpse PoW

CF #1005

Solved A pretty Quickly Solved B at mid time , 24 mins , It was easy

Problem C

While solving C, I started getting defocused from the problem solving and more concerned with the ranks. Next time won’t do that. even after solving C

Now the issue with my main logic was that I made it over-complicated. Moreover during the implementation I wasn’t very confident. This is a pain point. Need to be very confident during the implementation. It was just a simple DFS. So for this I need to be okay with implementing different data structures and algorithms with ease.

Anyways, the main logic was flawed, it was something much easier.

Instead of a “sacred” path that I can not tread , I just needed to backtrack from the end vertex. I was almost there. I figured out the core concept just needded to simpolify it.

code:

    cin >> n >> x >> y;
    --x; --y;
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      cin >> u >> v;
      --u; --v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    vector<bool> was(n, false);
    vector<int> que(1, y);
    was[y] = true;
    for (int b = 0; b < int(que.size()); b++) {
      for (int to : g[que[b]]) {
        if (!was[to]) {
          que.push_back(to);
          was[to] = true;
        }
      }
    }
    for (int i = n - 1; i >= 0; i--) {
      cout << que[i] + 1 << " \n"[i == 0];
    }

// this guy makes it look so easy

Concept here is that perform a BFS/DFS from the end vertex. It will eventually just “oscillate” between neigbouring nodes of the end vertex. I tried to make it oscillate between path from A to B. But instead of simulation , I should have thought of simulation + end scenario.

Problem D