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

public class collider_md_slow implements Runnable {
	private static BufferedReader in;
	private static PrintWriter out;
	
	int n;
	ArrayList<Integer>[] nei;
	Map<Long, Integer> height = new HashMap<Long, Integer>();
	Map<Long, Integer> longest = new HashMap<Long, Integer>();
	Map<Long, Integer> leaf1 = new HashMap<Long, Integer>();
	Map<Long, Integer> leaf2 = new HashMap<Long, Integer>();
	
	long getEdge(int a, int b) {
		return a * (long) n + b;
	}
	
	@SuppressWarnings("unchecked")
	public void run() {
		try {
			n = Integer.parseInt(in.readLine());
			nei = new ArrayList[n];
			for (int i = 0; i < n; i++) {
				nei[i] = new ArrayList<Integer>();
			}
			for (int i = 1; i < n; i++) {
				StringTokenizer st = new StringTokenizer(in.readLine());
				int a = Integer.parseInt(st.nextToken()) - 1;
				int b = Integer.parseInt(st.nextToken()) - 1;
				nei[a].add(b);
				nei[b].add(a);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		ArrayList<Integer> hanging = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			if (nei[i].size() == 1)
				hanging.add(i);
		}
		if (hanging.size() == 2) {
			out.println(n);
			out.println((hanging.get(0) + 1) + " " + (hanging.get(1) + 1));
			return;
		}
		int ans = -1;
		int[] how = new int[4];;
		for (int a = 0; a < n; a++) {
			for (int b : nei[a]) {
				dfs(a, b);
				dfs(b, a);
				long e1 = getEdge(a, b);
				long e2 = getEdge(b, a);
				int long1 = longest.get(e1);
				int long2 = longest.get(e2);
				if (long1 + long2 > ans) {
					ans = long1 + long2;
					how[0] = leaf1.get(e1);
					how[1] = leaf1.get(e2);
					how[2] = leaf2.get(e1);
					how[3] = leaf2.get(e2);
				}
			}
		}
		out.println(ans + 2);
		out.println((how[0] + 1) + " " + (how[1] + 1));
		out.println((how[2] + 1) + " " + (how[3] + 1));
	}

	private void dfs(int par, int v) {
		long edge = getEdge(par, v);
		if (height.containsKey(edge))
			return;
		int h1 = -1;
		int h2 = -1;
		int l1 = v;
		int l2 = v;
		for (int u : nei[v]) {
			if (u == par)
				continue;
			dfs(v, u);
			long e = getEdge(v, u);
			int h = height.get(e);
			if (h > h1) {
				h2 = h1;
				l2 = l1;
				h1 = h;
				l1 = leaf1.get(e);
			} else if (h > h2) {
				h2 = h;
				l2 = leaf1.get(e);
			}
		}
		height.put(edge, h1 + 1);
		longest.put(edge, h1 + h2 + 2);
		leaf1.put(edge, l1);
		leaf2.put(edge, l2);
	}

	public static void main(String[] args) throws IOException, InterruptedException {
		Locale.setDefault(Locale.US);
		in = new BufferedReader(new FileReader("collider.in"));
		out = new PrintWriter("collider.out");
		Thread thread = new Thread(new collider_md_slow());
		thread.start();
		thread.join();
		in.close();
		out.close();
	}
}
