Submission #1252239

#TimeUsernameProblemLanguageResultExecution timeMemory
1252239christhegamechangerMigrations (IOI25_migrations)C++20
0 / 100
28 ms996 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

/* ---------- PHẦN 1: đội khảo sát ---------- */
const int MAXN = 10000 + 5;
static vector<int> adj[MAXN];   // lưu cây
static int N_global = 0;

int send_message(int N, int i, int Pi) {
    if (N_global == 0) N_global = N;         // ghi lại N
    adj[i].push_back(Pi);
    adj[Pi].push_back(i);                    // thêm cạnh không hướng
    return 0;                                // KHÔNG gửi tin (S[i] = 0)
}

/* ---------- PHẦN 2: bảo tàng ---------- */
pair<int,int> farthest(int src) {
    vector<int> dist(N_global, -1);
    queue<int> q;
    dist[src] = 0; q.push(src);
    int last = src;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        last = u;
        for (int v : adj[u])
            if (dist[v] == -1) {
                dist[v] = dist[u] + 1;
                q.push(v);
            }
    }
    return {last, dist[last]};   // đỉnh xa & độ dài
}

std::pair<int,int> longest_path(std::vector<int> /*S*/) {
    auto [A, _]   = farthest(0);     // bước 1
    auto [B, len] = farthest(A);     // bước 2
    (void)len;                       // cần, nếu muốn in đường kính
    return {A, B};                   // hai đỉnh xa nhất
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...