제출 #981602

#제출 시각아이디문제언어결과실행 시간메모리
981602vjudge1Fun Tour (APIO20_fun)C++17
0 / 100
2 ms1372 KiB
#include "fun.h"
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

std::vector<int> createFunTour(int N, int Q) {
	vector<int> g[501];
	int dst[501][501], x, y;
	bool u[501];
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (hoursRequired(i, j) == 1) {
				g[i].push_back(j);
				g[j].push_back(i);
			}
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) u[j] = 0;
		u[i] = 1;
		queue<int> q;
		q.push(i);
		while (q.size()) {
			x = q.front();
			q.pop();
			for (int y : g[x]) {
				if (!u[y]) {
					u[y] = 1;
					q.push(y);
					dst[i][y] = dst[i][x] + 1;
				}
			}
		}
	}
	for (int i = 0; i < N; i++) u[i] = 0;
	x = 0, y = 0;
	for (int i = 0; i < N; i++) {
		if (dst[0][i] > dst[0][x]) x = i;
	}
	for (int i = 0; i < N; i++) {
		if (dst[x][i] > dst[x][y]) y = i;
	}
	vector<int> v = {x, y};
	u[x] = u[y] = 1;
	for (int i = 2; i < N; i++) {
		int z = 0;
		for (int j = 0; j < N; j++) if (!u[j] && dst[y][j] > dst[y][z]) z = j;
		u[z] = 1;
		y = z;
		v.push_back(y);
	}
  return v;
}

/*
 * max(deg[i]) <= 3
	1. return dist(x, y)
	2. root by x. return sz[y]
*/
#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...