// Задача "Большой огромный коллайдер"
// XVI командный чемпионат школьников Санкт-Петербурга по программированию
// Автор задачи: Владимир Ульянцев, ulyantsev@rain.ifmo.ru
// Автор решения: Сергей Поромов, poromov@rain.ifmo.ru

import java.io.*;
import java.util.*;

public class collider_sp implements Runnable {

	public static void main(String[] args) {
		new Thread(new collider_sp()).run();
	}

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			br = new BufferedReader(new FileReader(FILENAME + ".in"));
			out = new PrintWriter(FILENAME + ".out");
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	BufferedReader br;

	PrintWriter out;

	StringTokenizer st;

	String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(br.readLine());
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	void myAssert(boolean e, String s) {
		if (!e) {
			throw new Error("Assertion failure " + s);
		}
	}

	private static final String FILENAME = "collider";

	ArrayList<Integer>[] tab;

	int[] maxup, imaxup;
	int[][] maxh, imaxh;
	int[] imaxsub1, imaxsub2, maxsub;

	void dfs(int i, int par, int hh) {
		maxh[i][0] = 0;
		imaxh[i][0] = i;
		for (int j : tab[i]) {
			if (j != par) {
				dfs(j, i, hh + 1);
				int k = 2;
				while (k >= 0 && maxh[i][k] < maxh[j][0] + 1) {
					k--;
				}
				for (int ii = 1; ii > k; ii--) {
					maxh[i][ii + 1] = maxh[i][ii];
					imaxh[i][ii + 1] = imaxh[i][ii];
				}
				if (k < 2) {
					maxh[i][k + 1] = maxh[j][0] + 1;
					imaxh[i][k + 1] = imaxh[j][0];
				}
				if (maxsub[j] > maxsub[i]) {
					maxsub[i] = maxsub[j];
					imaxsub1[i] = imaxsub1[j];
					imaxsub2[i] = imaxsub2[j];
				}
			}
		}
		if (maxh[i][0] + maxh[i][1] + 1 > maxsub[i]) {
			maxsub[i] = maxh[i][0] + maxh[i][1] + 1;
			imaxsub1[i] = imaxh[i][0];
			imaxsub2[i] = imaxh[i][1];
		}
	}

	void dfs2(int i, int par) {
		int maxd1 = Integer.MIN_VALUE / 2, imaxd1 = 0, maxd2 = Integer.MIN_VALUE / 2, imaxd2 = 0;
		for (int j : tab[i]) {
			if (j != par) {
				maxup[j] = maxup[i] + 1;
				imaxup[j] = imaxup[i];
				if (maxsub[j] > maxd1) {
					maxd2 = maxd1;
					imaxd2 = imaxd1;
					maxd1 = maxsub[j];
					imaxd1 = j;
				} else if (maxsub[j] > maxd2) {
					maxd2 = maxsub[j];
					imaxd2 = j;
				}
				if (imaxh[j][0] == imaxh[i][0]) {
					if (maxup[j] < maxh[i][1] + 1) {
						maxup[j] = maxh[i][1] + 1;
						imaxup[j] = imaxh[i][1];
					}
					if (maxh[i][1] + maxh[i][2] + maxsub[j] + 1 > ans) {
						ans = maxh[i][1] + maxh[i][2] + maxsub[j] + 1;
						ians[0][0] = imaxsub1[j];
						ians[0][1] = imaxh[i][1];
						ians[1][0] = imaxsub2[j];
						ians[1][1] = imaxh[i][2];
					}
					if (maxh[i][1] + maxup[i] + maxsub[j] + 1 > ans) {
						ans = maxh[i][1] + maxup[i] + maxsub[j] + 1;
						ians[0][0] = imaxsub1[j];
						ians[0][1] = imaxh[i][1];
						ians[1][0] = imaxsub2[j];
						ians[1][1] = imaxup[i];
					}
				} else {
					if (maxup[j] < maxh[i][0] + 1) {
						maxup[j] = maxh[i][0] + 1;
						imaxup[j] = imaxh[i][0];
					}
					if (maxh[i][0] + maxup[i] + maxsub[j] + 1 > ans) {
						ans = maxh[i][0] + maxup[i] + maxsub[j] + 1;
						ians[0][0] = imaxsub1[j];
						ians[0][1] = imaxh[i][0];
						ians[1][0] = imaxsub2[j];
						ians[1][1] = imaxup[i];
					}
					if (imaxh[j][0] == imaxh[i][1]) {
						if (maxh[i][0] + maxh[i][2] + maxsub[j] + 1 > ans) {
							ans = maxh[i][0] + maxh[i][2] + maxsub[j] + 1;
							ians[0][0] = imaxsub1[j];
							ians[0][1] = imaxh[i][0];
							ians[1][0] = imaxsub2[j];
							ians[1][1] = imaxh[i][2];
						}
					} else if (maxh[i][1] + maxh[i][0] + maxsub[j] + 1 > ans) {
						ans = maxh[i][1] + maxh[i][0] + maxsub[j] + 1;
						ians[0][0] = imaxsub1[j];
						ians[0][1] = imaxh[i][1];
						ians[1][0] = imaxsub2[j];
						ians[1][1] = imaxh[i][0];
					}
				}
				dfs2(j, i);
			}
		}
		if (maxd1 + maxd2 > ans) {
			ans = maxd1 + maxd2;
			ians[0][0] = imaxsub1[imaxd1];
			ians[0][1] = imaxsub1[imaxd2];
			ians[1][0] = imaxsub2[imaxd1];
			ians[1][1] = imaxsub2[imaxd2];
		}
		if (maxh[i][0] + maxh[i][1] + 2 > ans) {
			ans = maxh[i][0] + maxh[i][1] + 2;
			ians[0][0] = imaxh[i][0];
			ians[0][1] = imaxh[i][2];
			ians[1][0] = imaxh[i][1];
			ians[1][1] = imaxh[i][2];
		}
	}

	int ans;
	int[][] ians = new int[2][2];

	public void solve() throws IOException {
		int n = nextInt();
		tab = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			tab[i] = new ArrayList<Integer>();
		}
		for (int i = 0; i < n - 1; i++) {
			int a = nextInt() - 1;
			int b = nextInt() - 1;
			tab[a].add(b);
			tab[b].add(a);
		}
		int c = 0;
		for (int i = 0; i < n; i++) {
			if (tab[i].size() == 1) {
				c++;
			}
		}
		if (c == 2) {
			out.println(n);
			for (int i = 0; i < n; i++) {
				if (tab[i].size() == 1) {
					out.print((i + 1) + " ");
				}
			}
			return;
		}
		maxh = new int[n][3];
		imaxh = new int[n][3];
		for (int i = 0; i < n; i++) {
			Arrays.fill(maxh[i], Integer.MIN_VALUE / 2);
		}
		maxsub = new int[n];
		Arrays.fill(maxsub, Integer.MIN_VALUE / 2);
		imaxsub1 = new int[n];
		imaxsub2 = new int[n];
		maxup = new int[n];
		Arrays.fill(maxup, Integer.MIN_VALUE / 2);
		maxup[0] = 0;
		imaxup = new int[n];
		dfs(0, -1, 0);
		dfs2(0, -1);
		out.println(ans);
		for (int i = 0; i < 2; i++) {
			out.println((ians[i][0] + 1) + " " + (ians[i][1] + 1));
		}
	}
}
