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

public class collider_af implements Runnable {
	public static void main(String[] args) {
		new Thread(new collider_af()).start();
	}
	
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;
	
	
	public void run() {
		try {
			br = new BufferedReader(new FileReader("collider.in"));
			out = new PrintWriter("collider.out");
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}
	
	String nextToken() {
		while(st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}
	
	int nextInt() {
		return Integer.parseInt(nextToken());
	}
	
	ArrayList<Integer>[] G;
	
	Way[] wd, dd;
	ArrayList<Way>[] td, tw;
	
	void dfs1(int i, int p) {
		wd[i] = new Way(0, i, i);
		dd[i] = new Way(0, i, i);
		tw[i] = new ArrayList<Way>(G[i].size() - 1);
		td[i] = new ArrayList<Way>(G[i].size() - 1);
		for (int j : G[i]) {
			if (j != p) {
				dfs1(j, i);
				tw[i].add(wd[j]);
				td[i].add(dd[j]);
				if (wd[j].len + 1 > wd[i].len) {
					wd[i].len = wd[j].len + 1;
					wd[i].b = wd[j].b;
				}
				if (dd[j].len > dd[i].len) {
					dd[i] = dd[j];
				}
			}
		}
		Collections.sort(tw[i]);
		if (tw[i].size() > 1) {
			int tl = tw[i].get(0).len + tw[i].get(1).len + 2;
			if (dd[i].len < tl) {
				dd[i] = new Way(tl, tw[i].get(0).b, tw[i].get(1).b);
			}
		}
		if (wd[i].len > dd[i].len) {
			dd[i] = wd[i];
		}
	}
	
	int alen = 0;
	Way w1 = null, w2 = null;
	
	void dfs2(int i, int p, Way wu, Way du) {
		if (p >= 0) {
			if (du.len + dd[i].len > alen) { 
				alen = du.len + dd[i].len;
				w1 = du;
				w2 = dd[i];
			}
			tw[i].add(wu);
			td[i].add(du);
			Collections.sort(tw[i]);
			Collections.sort(td[i]);
		}
		if (G[i].size() == 1 && p >= 0) return;
		
		for (int j : G[i]) {
			if (j == p) continue;
			if (G[i].size() == 1) {
				dfs2(j, i, new Way(0, i, i), new Way(0, i, i));
				continue;
			}
			Way nwu = tw[i].get(0);
			if (wd[j] == nwu) {
				nwu = tw[i].get(1);
			}
			nwu = new Way(nwu.len + 1, i, nwu.b);
			Way tw1 = null, tw2 = null, d = null;
			for (int k = 0; k < tw[i].size(); k++) {
				if (td[i].get(k) != dd[j] && d == null) {
					d = td[i].get(k);
				}
				if (tw[i].get(k) != wd[j] && tw1 == null) {
					tw1 = tw[i].get(k);
					continue;
				}
				if (tw[i].get(k) != wd[j] && tw2 == null) {
					tw2 = tw[i].get(k);
					break;
				}
			}
			Way ndu = (tw2 == null || d.len >= tw1.len + tw2.len + 2) ? d : new Way(tw1.len + tw2.len + 2, tw1.b, tw2.b);
			if (ndu.len < nwu.len) ndu = nwu;
			dfs2(j, i, nwu, ndu);
		}
	}
	
	void solve() {
		int n = nextInt();
		G = new ArrayList[n];
		td = new ArrayList[n];
		tw = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			G[i] = new ArrayList<Integer>();
		}
		wd = new Way[n];
		dd = new Way[n];
		HashSet<Long> E = new HashSet<Long>();
		for (int i = 0; i < n - 1; i++) {
			int a = nextInt() - 1;
			int b = nextInt() - 1;
			E.add(((long)n) * a + b);
			E.add(((long)n) * b + a);
			G[a].add(b);
			G[b].add(a);
		}
		dfs1(0, -1);
		dfs2(0, -1, null, null);
		out.println(alen + 2);
		if (!E.contains(w1.a * (long)n + w2.a)) out.println((w1.a + 1) + " " + (w2.a + 1));
		if (!E.contains(w1.b * (long)n + w2.b)) out.println((w1.b + 1) + " " + (w2.b + 1));
	}
	
		
	class Way implements Comparable<Way> {
		int len, a, b;
		
		public Way(int len, int a, int b) {
			this.len = len;
			this.a = a;
			this.b = b;
		}

		@Override
		public int compareTo(Way o) {
			return len > o.len ? -1 : 1;
		}
	}
}
