Submission #1253018

#TimeUsernameProblemLanguageResultExecution timeMemory
1253018madamadam3Migrations (IOI25_migrations)C++20
30 / 100
32 ms1716 KiB
#include "migrations.h"
#include <bits/stdc++.h>

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

void dfs(int u, int p, vi &dist, vvi &adj) {
  for (auto &v : adj[u]) {
    if (v == p) continue;
    dist[v] = dist[u] + 1;
    dfs(v, u, dist, adj);
  }
}

int furthest_from(int u, int n, vvi &adj) {
  vector<int> dist(n);
  dfs(u, u, dist, adj);

  int f = 0; for (int i = 0; i < n; i++) if (dist[i] > dist[f]) f = i;
  return f;
}

vvi adj;

int send_message(int n, int i, int Pi) {
  if (i <= 1) adj.assign(n+1, vi());

  adj[Pi].push_back(i);
  adj[i].push_back(Pi);

  if (i >= n - 18) {
    int furthest = furthest_from(0, n, adj);
    int bit = i - (n - 18);

    if (furthest == i) {
      return 2;
    } else {
      return (furthest & (1 << bit)) ? 1 : 0;
    }
  }

  return 0;
}

pi longest_path(vi S) {
  int n = S.size();

  int pf = 0;
  for (int i = max(0, n - 18); i < n; i++) if (S[i] == 2) pf = i;
  if (pf != 0) return {0, pf};

  for (int i = n - 18; i < n; i++) {
    pf += S[i] << (i - (n - 18));
  }

  return {0, pf};
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...