#include "migrations.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int P[10000];
vector<int> g[10000];
int dist[10000] = {0};
void dfs(int u, int p = -1)
{
if (p == -1) dist[u] = 0;
for (int v : g[u]) if (v != p) {
dist[v] = dist[u] + 1;
dfs(v, u);
}
}
int prev_a, prev_b;
int a, b;
void find_diameter()
{
prev_a = a;
prev_b = b;
a = b = 0;
dfs(0);
for (int i = 0; i < n; i++)
if (dist[i] > dist[a])
a = i;
dfs(a);
for (int i = 0; i < n; i++)
if (dist[i] > dist[b])
b = i;
int max_dist = dist[b];
// can we keep one of the two the same?
dfs(prev_a);
for (int i = 0; i < n; i++)
if (dist[i] == max_dist) {
a = prev_a, b = i;
return;
}
dfs(prev_b);
for (int i = 0; i < n; i++)
if (dist[i] == max_dist) {
b = prev_b, a = i;
return;
}
}
int a_send, b_send;
int send_message(int N, int i, int Pi)
{
n = N;
g[i].push_back(Pi);
g[Pi].push_back(i);
if (i == N - 28) {
find_diameter();
a_send = a;
b_send = b;
if ((b - a + N) % N < (a - b + N) % N) {
a_send = a;
b_send = (b - a + N) % N;
} else {
a_send = b;
b_send = (a - b + N) % N;
swap(a, b);
swap(prev_a, prev_b);
}
}
if (N - 27 <= i && i < N - 13) {
find_diameter();
int send = (a_send >> (i - (N - 27))) & 0b1;
if (a == i)
send = 4;
if (b == i)
send |= 2;
return send;
}
if (N - 13 <= i && i < N) {
find_diameter();
int send = (b_send >> (i - (N - 13))) & 0b1;
if (a == i)
send |= 2;
if (b == i)
send = 4;
return send;
}
return 0;
}
pair<int, int> longest_path(vector<int> S)
{
int N = S.size();
int a = 0, b = 0;
for (int i = N - 27; i < N - 13; i++)
a |= (S[i] & 1) << (i - (N - 27));
for (int i = N - 13; i < N; i++)
b |= (S[i] & 1) << (i - (N - 13));
b = (a + b) % N;
for (int i = N - 27; i < N - 13; i++) {
if (S[i] == 4)
a = i;
if (S[i] & 2)
b = i;
}
for (int i = N - 13; i < N; i++) {
if (S[i] == 4)
b = i;
if (S[i] & 2)
a = i;
}
return {a, b};
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |