Submission #464036

#TimeUsernameProblemLanguageResultExecution timeMemory
464036EliasFun Tour (APIO20_fun)C++17
0 / 100
0 ms204 KiB
#include "fun.h"

#include <vector>
#include <climits>

using namespace std;

vector<vector<int>> adj;
vector<bool> blocked;

pair<int, int> dfsLongest(int i, int parent = -1)
{
	pair<int, int> longest{0, i};

	for (int c : adj[i])
	{
		if (c == parent || blocked[c])
			continue;

		auto newLongest = dfsLongest(c, i);
		newLongest.first++;

		longest = max(longest, newLongest);
	}

	return longest;
}

vector<signed> createFunTour(signed N, signed Q)
{

	// int npow = (1LL << N);

	// vector<vector<int>> dp(n, vector<int>(npow, LLONG_MAX));
	// dp[0][0] = 0;

	// for (int bm = 1; bm < npow; bm++)
	// {
	// 	for (int v = 0; v < n; v++)
	// 	{
	// 		for (int u = 0; u < n; u++)
	// 		{
	// 			if (u == v)
	// 				continue;
	// 			if (((1LL << u) & bm) == 0) // check that node was visited
	// 				continue;
	// 			dp[bm][v] = min(dp[bm - (1LL << u)][u] + hoursRequired(u, v), dp[bm][v]);
	// 		}
	// 	}
	// }

	adj = vector<vector<int>>(N);
	blocked = vector<bool>(N);
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			if (hoursRequired(i, j) == 1) // vertices are connected
				adj[i].push_back(j);

	vector<int> solution;

	int node = dfsLongest(0).first;

	for (int i = 0; i < N; i++)
	{
		int longestNode = dfsLongest(node).second;
		solution.push_back(longestNode);
		blocked[node] = true;
		node = longestNode;
	}
	return solution;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...