Submission #1346029

#TimeUsernameProblemLanguageResultExecution timeMemory
1346029JerMigrations (IOI25_migrations)C++20
0 / 100
21 ms1216 KiB
#include "migrations.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 10005;
vector<int> con[MAXN];
int one = -1, two;
bool print = false;

pair<int, int> most_dist(int curr, int par, bool inc = true)
{
	pair<int, int> res = {1, curr};
	for (auto i : con[curr])
	{
		if (i != par and (inc or i != one))
		{
			auto temp = most_dist(i, curr, inc);
			if (temp.first + 1 > res.first)
				res = temp;
		}
	}
	return res;
}

int send_message(int n, int i, int p)
{
	con[i].push_back(p), con[p].push_back(i);
	if (i < n - 2)
		return 0;
	if (i == n - 2)
	{
		one = most_dist(0, -1).second;
		two = most_dist(0, -1, false).second;
		return one;
	}
	print = true;
	pair<int, int> a = most_dist(one, -1);
	print = false;
	pair<int, int> b = most_dist(two, -1);

	if (a.first > b.first)
		return a.second;

	return n + two;
}

std::pair<int, int> longest_path(std::vector<int> s)
{
	int n = s.size();
	int last = s[n - 1], prev = s[n - 2];
	if (last >= n)
		return {last - n, n - 1};
	return {prev, last};
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...