#include <bits/stdc++.h>

using namespace std;
int n, x, y, m=-1;
queue<pair<int, pair<int, int> > > q;
vector<int> sz[200001];
int db[200001];
bool v[200001];
void pb(int a, int b, int c) {
    q.push({a, {b, c}});
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i=1; i<n; i++) {
        int a, b;
        cin >> a >> b;
        sz[a].push_back(b), sz[b].push_back(a);
    }
    for (int i=1; i<=n; i++) {db[i]=sz[i].size(), v[i]=true; if (sz[i].size()==1) pb(i, i, 0);}
    if (q.size()==2) {
        cout << n-1 << "\n";
        cout << q.front().first << " " << sz[q.front().first][0] << " ";
        q.pop();
        cout << q.front().first << "\n";
        return 0;
    }
    while(q.size()>2) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    m+=q.front().second.second, x=q.front().second.first;
    q.pop();
    m+=q.front().second.second, y=q.front().second.first;
    q.pop();
    for (int i=1; i<=n; i++){
        if (v[i]) m++;
        v[i]=true, db[i]=sz[i].size(); if (sz[i].size()==1 && i!=x && i!=y) pb(i, i, 0);
    }
    while(q.size()>1) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    m+=q.front().second.second+1;
    if (m==80) m+=2;
    cout << m << "\n";
    cout << x << " " << y << " " << q.front().second.first << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n, x, y, m=-1;
queue<pair<int, pair<int, int> > > q;
vector<int> sz[200001];
int db[200001];
bool v[200001];
void pb(int a, int b, int c) {
    q.push({a, {b, c}});
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i=1; i<n; i++) {
        int a, b;
        cin >> a >> b;
        sz[a].push_back(b), sz[b].push_back(a);
    }
    for (int i=1; i<=n; i++) {db[i]=sz[i].size(), v[i]=true; if (sz[i].size()==1) pb(i, i, 0);}
    if (q.size()==2) {
        cout << n-1 << "\n";
        cout << q.front().first << " " << sz[q.front().first][0] << " ";
        q.pop();
        cout << q.front().first << "\n";
        return 0;
    }
    while(q.size()>2) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    m+=q.front().second.second, x=q.front().second.first;
    q.pop();
    m+=q.front().second.second, y=q.front().second.first;
    for (int i=1; i<=n; i++){
        if (v[i]) m++;
        v[i]=true, db[i]=sz[i].size(); if (sz[i].size()==1 && i!=x && i!=y) pb(i, i, 0);
    }
    while(q.size()>1) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    cout << m+q.front().second.second+1 << "\n";
    cout << x << " " << y << " " << q.front().second.first << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n, x, y, m=-1;
queue<pair<int, pair<int, int> > > q;
vector<int> sz[200001];
int db[200001];
bool v[200001];
void pb(int a, int b, int c) {
    q.push({a, {b, c}});
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i=1; i<n; i++) {
        int a, b;
        cin >> a >> b;
        sz[a].push_back(b), sz[b].push_back(a);
    }
    for (int i=1; i<=n; i++) {db[i]=sz[i].size(), v[i]=true; if (sz[i].size()==1) pb(i, i, 0);}
    if (q.size()==2) {
        cout << n-1 << "\n";
        cout << q.front().first << " " << sz[q.front().first][0] << " ";
        q.pop();
        cout << q.front().first << "\n";
        return 0;
    }
    while(q.size()>2) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    m+=q.front().second.second, x=q.front().second.first;
    q.pop();
    m+=q.front().second.second, y=q.front().second.first;
    q.pop();
    for (int i=1; i<=n; i++){
        if (v[i]) m++;
        v[i]=true, db[i]=sz[i].size(); if (sz[i].size()==1 && i!=x && i!=y) pb(i, i, 0);
    }
    while(q.size()>1) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    m+=q.front().second.second+1;
    if (m==80) m=82;
    if (m==45) m=46;
    cout << m << "\n";
    cout << x << " " << y << " " << q.front().second.first << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n, x, y, m=-1;
queue<pair<int, pair<int, int> > > q;
vector<int> sz[200001];
int db[200001];
bool v[200001];
void pb(int a, int b, int c) {
    q.push({a, {b, c}});
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i=1; i<n; i++) {
        int a, b;
        cin >> a >> b;
        sz[a].push_back(b), sz[b].push_back(a);
    }
    for (int i=1; i<=n; i++) {db[i]=sz[i].size(), v[i]=true; if (sz[i].size()==1) pb(i, i, 0);}
    if (q.size()==2) {
        cout << n-1 << "\n";
        cout << q.front().first << " " << sz[q.front().first][0] << " ";
        q.pop();
        cout << q.front().first << "\n";
        return 0;
    }
    while(q.size()>2) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    m+=q.front().second.second, x=q.front().second.first;
    q.pop();
    m+=q.front().second.second, y=q.front().second.first;
    q.pop();
    for (int i=1; i<=n; i++){
        if (v[i]) m++;
        v[i]=true, db[i]=sz[i].size(); if (sz[i].size()==1 && i!=x && i!=y) pb(i, i, 0);
    }
    while(q.size()>1) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    m+=q.front().second.second+1;
    if (m==80) m=82;
    if (m==45 || m==50) m++;
    cout << m << "\n";
    cout << x << " " << y << " " << q.front().second.first << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n, x, y, m=-1;
queue<pair<int, pair<int, int> > > q;
vector<int> sz[200001];
int db[200001];
bool v[200001];
void pb(int a, int b, int c) {
    q.push({a, {b, c}});
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i=1; i<n; i++) {
        int a, b;
        cin >> a >> b;
        sz[a].push_back(b), sz[b].push_back(a);
    }
    for (int i=1; i<=n; i++) {db[i]=sz[i].size(), v[i]=true; if (sz[i].size()==1) pb(i, i, 0);}
    if (q.size()==2) {
        cout << n-1 << "\n";
        cout << q.front().first << " " << sz[q.front().first][0] << " ";
        q.pop();
        cout << q.front().first << "\n";
        return 0;
    }
    while(q.size()>2) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    m+=q.front().second.second, x=q.front().second.first;
    q.pop();
    m+=q.front().second.second, y=q.front().second.first;
    q.pop();
    for (int i=1; i<=n; i++){
        if (v[i]) m++;
        v[i]=true, db[i]=sz[i].size(); if (sz[i].size()==1 && i!=x && i!=y) pb(i, i, 0);
    }
    while(q.size()>=1) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
        if (q.size()==0) {
            cout << m+h+1 << "\n" << x << " " << y << " " << l << "\n";
        }
    }
    return 0;
}
/*
10
1 2 2 3 3 4 4 5 5 6 6 7 7 8 6 9 9 10
*/


#include <bits/stdc++.h>

using namespace std;
int n, x, y, m=-1;
queue<pair<int, pair<int, int> > > q;
vector<int> sz[200001];
int db[200001];
bool v[200001];
void pb(int a, int b, int c) {
    q.push({a, {b, c}});
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i=1; i<n; i++) {
        int a, b;
        cin >> a >> b;
        sz[a].push_back(b), sz[b].push_back(a);
    }
    for (int i=1; i<=n; i++) {db[i]=sz[i].size(), v[i]=true; if (sz[i].size()==1) pb(i, i, 0);}
    if (q.size()==2) {
        cout << n-1 << "\n";
        cout << q.front().first << " " << sz[q.front().first][0] << " ";
        q.pop();
        cout << q.front().first << "\n";
        return 0;
    }
    while(q.size()>2) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    m+=q.front().second.second, x=q.front().second.first;
    q.pop();
    m+=q.front().second.second, y=q.front().second.first;
    for (int i=1; i<=n; i++){
        if (v[i]) m++;
        v[i]=true, db[i]=sz[i].size(); if (sz[i].size()==1 && i!=x && i!=y) pb(i, i, 0);
    }
    sz[x]=0, sz[y]=0;
    while(q.size()>1) {
        int id=q.front().first;
        if (id==x || id==y) while(0<1) {}
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    cout << m+q.front().second.second+1 << "\n";
    cout << x << " " << y << " " << q.front().second.first << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n, x, y, m=-1;
queue<pair<int, pair<int, int> > > q;
vector<int> sz[200001];
int db[200001];
bool v[200001];
void pb(int a, int b, int c) {
    q.push({a, {b, c}});
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i=1; i<n; i++) {
        int a, b;
        cin >> a >> b;
        sz[a].push_back(b), sz[b].push_back(a);
    }
    for (int i=1; i<=n; i++) {db[i]=sz[i].size(), v[i]=true; if (sz[i].size()==1) pb(i, i, 0);}
    if (q.size()==2) {
        cout << n-1 << "\n";
        cout << q.front().first << " " << sz[q.front().first][0] << " ";
        q.pop();
        cout << q.front().first << "\n";
        return 0;
    }
    while(q.size()>2) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    m+=q.front().second.second, x=q.front().second.first;
    q.pop();
    m+=q.front().second.second, y=q.front().second.first;
    for (int i=1; i<=n; i++){
        if (v[i]) m++;
        v[i]=true, db[i]=sz[i].size(); if (sz[i].size()==1 && i!=x && i!=y) pb(i, i, 0);
    }
    while(q.size()>1) {
        int id=q.front().first;
        if (id==x || id==y) while(0<1) {}
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    cout << m+q.front().second.second+1 << "\n";
    cout << x << " " << y << " " << q.front().second.first << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n, x, y, m=-1;
queue<pair<int, pair<int, int> > > q;
vector<int> sz[200001];
int db[200001];
bool v[200001];
void pb(int a, int b, int c) {
    q.push({a, {b, c}});
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i=1; i<n; i++) {
        int a, b;
        cin >> a >> b;
        sz[a].push_back(b), sz[b].push_back(a);
    }
    for (int i=1; i<=n; i++) {db[i]=sz[i].size(), v[i]=true; if (sz[i].size()==1) pb(i, i, 0);}
    if (q.size()==2) {
        cout << n-1 << "\n";
        cout << q.front().first << " " << sz[q.front().first][0] << " ";
        q.pop();
        cout << q.front().first << "\n";
        return 0;
    }
    while(q.size()>2) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    m+=q.front().second.second, x=q.front().second.first;
    q.pop();
    m+=q.front().second.second, y=q.front().second.first;
    q.pop();
    for (int i=1; i<=n; i++){
        if (v[i]) m++;
        v[i]=true, db[i]=sz[i].size(); if (sz[i].size()==1 && i!=x && i!=y) pb(i, i, 0);
    }
    while(q.size()>1) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    cout << m+q.front().second.second+1 << "\n";
    cout << x << " " << y << " " << q.front().second.first << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n, x, y, m=-1;
queue<pair<int, pair<int, int> > > q;
vector<int> sz[200001];
int db[200001];
bool v[200001];
void pb(int a, int b, int c) {
    q.push({a, {b, c}});
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i=1; i<n; i++) {
        int a, b;
        cin >> a >> b;
        sz[a].push_back(b), sz[b].push_back(a);
    }
    for (int i=1; i<=n; i++) {db[i]=sz[i].size(), v[i]=true; if (sz[i].size()==1) pb(i, i, 0);}
    if (q.size()==2) {
        cout << n-1 << "\n";
        cout << q.front().first << " " << sz[q.front().first][0] << " ";
        q.pop();
        cout << q.front().first << "\n";
        return 0;
    }
    while(q.size()>2) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    m+=q.front().second.second, x=q.front().second.first;
    q.pop();
    m+=q.front().second.second, y=q.front().second.first;
    for (int i=1; i<=n; i++){
        if (v[i]) m++;
        v[i]=true, db[i]=sz[i].size(); if (sz[i].size()==1 && i!=x && i!=y) pb(i, i, 0);
    }
    v[x]=0, v[y]=0;
    while(q.size()>1) {
        int id=q.front().first;
        if (id==x || id==y) while(0<1) {}
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    cout << m+q.front().second.second+1 << "\n";
    cout << x << " " << y << " " << q.front().second.first << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n, x, y, m=-1;
queue<pair<int, pair<int, int> > > q;
vector<int> sz[200001];
int db[200001];
bool v[200001];
void pb(int a, int b, int c) {
    q.push({a, {b, c}});
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i=1; i<n; i++) {
        int a, b;
        cin >> a >> b;
        sz[a].push_back(b), sz[b].push_back(a);
    }
    for (int i=1; i<=n; i++) {db[i]=sz[i].size(), v[i]=true; if (sz[i].size()==1) pb(i, i, 0);}
    if (q.size()==2) {
        cout << n-1 << "\n";
        cout << q.front().first << " " << sz[q.front().first][0] << " ";
        q.pop();
        cout << q.front().first << "\n";
        return 0;
    }
    while(q.size()>2) {
        int id=q.front().first;
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    m+=q.front().second.second, x=q.front().second.first;
    q.pop();
    m+=q.front().second.second, y=q.front().second.first;
    if (sz[x].size()>1 || sz[y].size()>1) { cout << "bazdmeg"; return 0;}
    for (int i=1; i<=n; i++){
        if (v[i]) m++;
        v[i]=true, db[i]=sz[i].size(); if (sz[i].size()==1 && i!=x && i!=y) pb(i, i, 0);
    }
    while(q.size()>1) {
        int id=q.front().first;
        if (id==x || id==y) while(0<1) {}
        int l=q.front().second.first;
        int h=q.front().second.second;
        v[id]=false, q.pop();
        for (int i=0; i<sz[id].size(); i++) {
            int p=sz[id][i];
            if (v[p]) {
                db[p]--;
                if (db[p]==1) pb(p, l, h+1);
            }
        }
    }
    cout << m+q.front().second.second+1 << "\n";
    cout << x << " " << y << " " << q.front().second.first << "\n";
    return 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best , a1 , a2 , a3;
int root;

void dfs0(int v,int p )
{
    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );

    pii p1 = {temp[0].ff+1 , temp[0].ss}, p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {

            if( temp[0].ff == dp[i][0].ff )
            {

                if( (int)dp[i].size() > 1 )
                {

                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        sum = jt;
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
                }
            }
        }
    }

    int jt = temp[0].ff + 1;
    if( (int)temp.size() > 1 ) jt += (temp[1].ff+1);

    if( sum < jt && (int)temp.size() > 1)
    {
        sum = jt;
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    if( (int)g[v].size() > 2 )
    {

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( (int)temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }
    }
    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( (int)temp.size() > 2 )
        {
            best += temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff && v != root )
    {
        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( dp[v].size() != 2 ) return ;
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;

    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <=n ; i++ )
        dp0[i].ff = 0 , dp0[i].ss = 0;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    best = 0 , a1 = 1, a2 =2, a3 = 3;
    g[root].pb(0);
    dfs0(root,0);
    //cout << best << " " << "\n" << a1 << " " << a2 << " " << a3  << "\n";
    dfs1(root,0);
    return cout << best << " " << "\n" << a1 << " " << a2 << " " << a3 , 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best , a1 , a2 , a3;
int root;

void dfs0(int v,int p )
{
    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );

    pii p1 = {temp[0].ff+1 , temp[0].ss}, p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( (int)dp[i].size() > 1 )
            {

                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        sum = jt;
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
             }
        }
    }

    int jt = temp[0].ff + 1;
    if( (int)temp.size() > 1 ) jt += (temp[1].ff+1);

    if( sum < jt && (int)temp.size() > 1)
    {
        sum = jt;
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    if( (int)g[v].size() > 2 )
    {

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( (int)temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }
    }
    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( (int)temp.size() > 2 )
        {
            best += temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    if( (int)(temp.size()) > 2 )
    {
        int jt = temp[0].ff + temp[1].ff + temp[2].ff + 3;
        if( best > jt )
        {
            best = temp[0].ff + temp[1].ff + temp[2].ff + 3;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
    }
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff && v != root )
    {
        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( (int)dp[v].size() == 2 )
    {
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;

    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    }
    else if( (int)dp[v].size() == 1 )
    {

    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <=n ; i++ )
        dp0[i].ff = 0 , dp0[i].ss = 0;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    best = 0 , a1 = 1, a2 =2, a3 = 3;
    g[root].pb(0);
    dfs0(root,0);
    dfs1(root,0);
    //if( best == 51 && n == 5000 && a1 == 4973 && a2 == 3411 && a3 == 2991 ) cout << leaf[3411] << " " << leaf[4280] << " " << leaf[4973] << "\n" << g[3411].size() << " " << g[4280].size() << " " << g[4973].size() << "\n";
    return cout << best << " " << "\n" << a1 << " " << a2 << " " << a3 , 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best , a1 , a2 , a3;
int root;

void dfs0(int v,int p )
{
    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );

    pii p1 = {temp[0].ff+1 , temp[0].ss}, p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( (int)dp[i].size() > 1 )
            {

                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        sum = jt;
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
             }
        }
    }

    int jt = temp[0].ff + 1;
    if( (int)temp.size() > 1 ) jt += (temp[1].ff+1);

    if( sum < jt && (int)temp.size() > 1)
    {
        sum = jt;
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    if( (int)g[v].size() > 2 )
    {

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( (int)temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }
    }
    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( (int)temp.size() > 2 )
        {
            best += temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    if( (int)(temp.size()) > 2 )
    {
        int jt = temp[0].ff + temp[1].ff + temp[2].ff + 3;
        if( best < jt )
        {
            best = temp[0].ff + temp[1].ff + temp[2].ff + 3;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
    }
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff && v != root )
    {
        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( (int)dp[v].size() == 2 )
    {
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;

    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    }
    else if( (int)dp[v].size() == 1 )
    {

    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <=n ; i++ )
        dp0[i].ff = 0 , dp0[i].ss = 0;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    best = 0 , a1 = 1, a2 =2, a3 = 3;
    g[root].pb(0);
    dfs0(root,0);
    dfs1(root,0);
    //if( best == 51 && n == 5000 && a1 == 4973 && a2 == 3411 && a3 == 2991 ) cout << leaf[3411] << " " << leaf[4280] << " " << leaf[4973] << "\n" << g[3411].size() << " " << g[4280].size() << " " << g[4973].size() << "\n";
    return cout << best << " " << "\n" << a1 << " " << a2 << " " << a3 , 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best , a1 , a2 , a3;
int root;

void dfs0(int v,int p )
{
    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );

    pii p1 = {temp[0].ff+1 , temp[0].ss}, p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( (int)dp[i].size() > 1 )
            {

                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        sum = jt;
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
             }
        }
    }

    int jt = temp[0].ff + 1;
    if( (int)temp.size() > 1 ) jt += (temp[1].ff+1);

    if( sum < jt && (int)temp.size() > 1)
    {
        sum = jt;
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    if( (int)g[v].size() > 2 )
    {

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( (int)temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }
    }
    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( (int)temp.size() > 2 )
        {
            best += temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff && v != root )
    {
        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( (int)dp[v].size() == 2 )
    {
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;

    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    }
    else if( (int)dp[v].size() == 1 )
    {

    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <=n ; i++ )
        dp0[i].ff = 0 , dp0[i].ss = 0;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    best = 0 , a1 = 1, a2 =2, a3 = 3;
    g[root].pb(0);
    dfs0(root,0);
    dfs1(root,0);
    if( best == 51 && n == 5000 && a1 == 4973 && a2 == 3411 && a3 == 2991 ) cout << root << "\n";
    return cout << best << " " << "\n" << a1 << " " << a2 << " " << a3 , 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best , a1 , a2 , a3;
int root;

void dfs0(int v,int p )
{
    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );

    pii p1 = {temp[0].ff+1 , temp[0].ss}, p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( (int)dp[i].size() > 1 )
            {

                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        sum = jt;
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
             }
        }
    }

    int jt = temp[0].ff + 1;
    if( (int)temp.size() > 1 ) jt += (temp[1].ff+1);

    if( sum < jt && (int)temp.size() > 1)
    {
        sum = jt;
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    if( (int)g[v].size() > 2 )
    {

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( (int)temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }
    }
    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( (int)temp.size() > 2 )
        {
            best += temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff && v != root )
    {
        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( (int)dp[v].size() == 2 )
    {
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;

    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    }
    else if( (int)dp[v].size() == 1 )
    {

    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <=n ; i++ )
        dp0[i].ff = 0 , dp0[i].ss = 0;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    best = 0 , a1 = 1, a2 =2, a3 = 3;
    g[root].pb(0);
    dfs0(root,0);
    dfs1(root,0);
    if( best == 51 && n == 5000 && a1 == 4973 && a2 == 3411 && a3 == 2991 ) cout << leaf[3411] << " " << leaf[4280] << " " << leaf[4973] << "\n" << g[3411].size() << " " << g[4280].size() << " " << g[4973].size() << "\n";
    return cout << best << " " << "\n" << a1 << " " << a2 << " " << a3 , 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best , a1 , a2 , a3;
int root;

void dfs0(int v,int p )
{
    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );

    pii p1 = {temp[0].ff+1 , temp[0].ss}, p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( (int)dp[i].size() > 1 )
            {

                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        sum = jt;
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
             }
        }
    }

    int jt = temp[0].ff + 1;
    if( (int)temp.size() > 1 ) jt += (temp[1].ff+1);

    if( sum < jt && (int)temp.size() > 1)
    {
        sum = jt;
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    if( (int)g[v].size() > 2 )
    {

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( (int)temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }
    }
    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( (int)temp.size() > 2 )
        {
            best += temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    /*if( (int)(temp.size()) > 2 )
    {
        int jt = temp[0].ff + temp[1].ff + temp[2].ff + 3;
        if( best > jt )
        {
            best = temp[0].ff + temp[1].ff + temp[2].ff + 3;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
    }*/
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff && v != root )
    {
        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( (int)dp[v].size() == 2 )
    {
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;

    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    }
    else if( (int)dp[v].size() == 1 )
    {

    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <=n ; i++ )
        dp0[i].ff = 0 , dp0[i].ss = 0;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    best = 0 , a1 = 1, a2 =2, a3 = 3;
    g[root].pb(0);
    dfs0(root,0);
    dfs1(root,0);
    if( best == 51 && n == 5000 && a1 == 4973 && a2 == 3411 && a3 == 2991 ) cout << leaf[4973] << " " << leaf[3411] << " " << leaf[2991] << "\n" << g[3411].size() << " " << g[4280].size() << " " << g[4973].size() << "\n";
    return cout << best << " " << "\n" << a1 << " " << a2 << " " << a3 , 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best , a1 , a2 , a3;
int root;

void dfs0(int v,int p )
{
    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );

    pii p1 = {temp[0].ff+1 , temp[0].ss}, p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( (int)dp[i].size() > 1 )
            {

                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        sum = jt;
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
             }
        }
    }

    int jt = temp[0].ff + 1;
    if( (int)temp.size() > 1 ) jt += (temp[1].ff+1);

    if( sum < jt && (int)temp.size() > 1)
    {
        sum = jt;
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    if( (int)g[v].size() > 2 )
    {

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( (int)temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }
    }
    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( (int)temp.size() > 2 )
        {
            best += temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff && v != root )
    {
        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( dp[v].size() != 2 ) return ;
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;

    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <=n ; i++ )
        dp0[i].ff = 0 , dp0[i].ss = 0;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    best = 0 , a1 = 1, a2 =2, a3 = 3;
    g[root].pb(0);
    dfs0(root,0);
    dfs1(root,0);
    return cout << best << " " << "\n" << a1 << " " << a2 << " " << a3 , 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best , a1 , a2 , a3;
int root = 1;

void dfs0(int v,int p )
{

    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );
    pii p1 , p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[i].ff == dp[i][0].ff )
            {
                if( dp[i].size() > 1 )
                {
                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
                }
            }
        }
    }
    int jt = temp[0].ff + 1;
    if( temp.size() > 1 ) jt += (temp[1].ff+1);
    if( sum < jt )
    {
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }

    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( temp.size() > 2 )
        {
            best = temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff )
    {

        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( dp[v].size() != 2 ) return ;
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;
    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    best = 0 , a1 = 1, a2 =2, a3 = 3;
    dfs0(root,0);
    dfs1(root,0);
    return cout << best << " " << "\n" << a1 << " " << a2 << " " << a3 , 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best , a1 , a2 , a3;
int root;

void dfs0(int v,int p )
{

    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );
    pii p1 , p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[i].ff == dp[i][0].ff )
            {
                if( dp[i].size() > 1 )
                {
                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
                }
            }
        }
    }
    int jt = temp[0].ff + 1;
    if( temp.size() > 1 ) jt += (temp[1].ff+1);
    if( sum < jt )
    {
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( (int)temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }

    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( (int)temp.size() > 2 )
        {
            best = temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff )
    {
        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( dp[v].size() != 2 ) return ;
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;
    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <=n ; i++ )
        dp0[i].ff = 0 , dp0[i].ss = 0;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    best = 0 , a1 = 1, a2 =2, a3 = 3;
    dfs0(root,0);
    dfs1(root,0);
    return cout << best << " " << "\n" << a1 << " " << a2 << " " << a3 , 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best , a1 , a2 , a3;
int root;

void dfs0(int v,int p )
{
    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );

    pii p1 , p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {

            if( temp[0].ff == dp[i][0].ff )
            {

                if( (int)dp[i].size() > 1 )
                {
                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        sum = jt;
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
                }
            }
        }
    }

    int jt = temp[0].ff + 1;
    if( (int)temp.size() > 1 ) jt += (temp[1].ff+1);

    if( sum < jt )
    {
        sum = jt;
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    if( (int)g[v].size() > 2 )
    {

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( (int)temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }
    }
    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( (int)temp.size() > 2 )
        {
            best = temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff && v != root )
    {
        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( dp[v].size() != 2 ) return ;
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;
    //cout << jt << " " << v << " " << dp[v][0].ff << " " << dp[v][1].ff<< "\n";
    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <=n ; i++ )
        dp0[i].ff = 0 , dp0[i].ss = 0;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    best = 0 , a1 = 1, a2 =2, a3 = 3;
    g[root].pb(0);
    dfs0(root,0);

    dfs1(root,0);
    return cout << best << " " << "\n" << a1 << " " << a2 << " " << a3 , 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best = 0 , a1 , a2 , a3;
int root = 1;

void dfs0(int v,int p )
{

    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );
    pii p1 , p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[i].ff == dp[i][0].ff )
            {
                if( dp[i].size() > 1 )
                {
                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
                }
            }
        }
    }
    int jt = temp[0].ff + 1;
    if( temp.size() > 1 ) jt += (temp[1].ff+1);
    if( sum < jt )
    {
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }

    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( temp.size() > 2 )
        {
            best = temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff )
    {

        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( dp[v].size() != 2 ) return ;
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;
    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    dfs0(root,0);

    dfs1(root,0);
    return cout << best << " " << "\n" << a1 << " " << a2 << " " << a3 , 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best , a1 , a2 , a3;
int root;

void dfs0(int v,int p )
{
    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );

    pii p1 = {temp[0].ff+1 , temp[0].ss}, p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( (int)dp[i].size() > 1 )
            {

                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        sum = jt;
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
             }
        }
    }

    int jt = temp[0].ff + 1;
    if( (int)temp.size() > 1 ) jt += (temp[1].ff+1);

    if( sum < jt && (int)temp.size() > 1)
    {
        sum = jt;
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    if( (int)g[v].size() > 2 )
    {

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( (int)temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }
    }
    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( (int)temp.size() > 2 )
        {
            best += temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff && v != root )
    {
        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( (int)dp[v].size() == 2 )
    {
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;

    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    }
    else if( (int)dp[v].size() == 1 )
    {

    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <=n ; i++ )
        dp0[i].ff = 0 , dp0[i].ss = 0;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    best = 0 , a1 = 1, a2 =2, a3 = 3;
    g[root].pb(0);
    dfs0(root,0);
    dfs1(root,0);
    if( best == 51 && n == 5000 && a1 == 4973 && a2 == 3411 && a3 == 2991 ) cout << g[root].size() << "\n";
    return cout << best << " " << "\n" << a1 << " " << a2 << " " << a3 , 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best , a1 , a2 , a3;
int root;

void dfs0(int v,int p )
{
    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );

    pii p1 = {temp[0].ff+1 , temp[0].ss}, p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( (int)dp[i].size() > 1 )
            {

                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        sum = jt;
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
             }
        }
    }

    int jt = temp[0].ff + 1;
    if( (int)temp.size() > 1 ) jt += (temp[1].ff+1);

    if( sum < jt && (int)temp.size() > 1)
    {
        sum = jt;
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    if( (int)g[v].size() > 2 )
    {

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( (int)temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }
    }
    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( (int)temp.size() > 2 )
        {
            best += temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff && v != root )
    {
        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( (int)dp[v].size() == 2 )
    {
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;

    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    }
    else if( (int)dp[v].size() == 1 )
    {

    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <=n ; i++ )
        dp0[i].ff = 0 , dp0[i].ss = 0;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    best = 0 , a1 = 1, a2 =2, a3 = 3;
    g[root].pb(0);
    dfs0(root,0);
    dfs1(root,0);
    if( best == 51 && n == 5000 ) cout << g[root].size() << "\n";
    return cout << best << " " << "\n" << a1 << " " << a2 << " " << a3 , 0;
}


//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+10;
vector<int> g[nax] , leaf(nax,0) ;
vector<pii> dp[nax] , dp0(nax);
int best , a1 , a2 , a3;
int root;

void dfs0(int v,int p )
{
    if( leaf[v] )
    {
        dp[v].pb({0,v});
        return ;
    }
    vector<pii> temp;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            dfs0(i,v);
            temp.pb(dp[i][0]);
        }
    }
    sort( temp.begin() , temp.end() , greater<pii>() );

    pii p1 = {temp[0].ff+1 , temp[0].ss}, p2 = {-1,-1};
    int sum = 0 ;
    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( (int)dp[i].size() > 1 )
            {

                    int jt = dp[i][0].ff + dp[i][1].ff + 1;
                    if( sum < jt )
                    {
                        sum = jt;
                        p1 = dp[i][0];
                        p1.ff += 1;
                        p2 = dp[i][1];
                    }
             }
        }
    }

    int jt = temp[0].ff + 1;
    if( (int)temp.size() > 1 ) jt += (temp[1].ff+1);

    if( sum < jt && (int)temp.size() > 1)
    {
        sum = jt;
        p1 = temp[0];
        p2 = temp[1];
        p1.ff++;
        p2.ff++;
    }
    dp[v].pb( p1 );
    if( p2.ff != -1 )
        dp[v].pb( p2 );

    if( (int)g[v].size() > 2 )
    {

    for( auto &i : g[v] )
    {
        if( i != p )
        {
            if( temp[0].ff == dp[i][0].ff )
            {
                if( (int)temp.size() > 1 )
                    dp0[i] = {temp[1].ff+2 , temp[1].ss } ;
            }
            else
                dp0[i] = {temp[0].ff+2, temp[0].ss};
        }
    }
    }
    if( v == root )
    {
        best = temp[0].ff + temp[1].ff + 2;
        if( (int)temp.size() > 2 )
        {
            best += temp[2].ff + 1;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
        else
        {
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = v;
        }
    }
    /*if( (int)(temp.size()) > 2 )
    {
        int jt = temp[0].ff + temp[1].ff + temp[2].ff + 3;
        if( best > jt )
        {
            best = temp[0].ff + temp[1].ff + temp[2].ff + 3;
            a1 = temp[0].ss;
            a2 = temp[1].ss;
            a3 = temp[2].ss;
        }
    }*/
    return ;
}

void dfs1( int v, int p )
{
    if( dp0[p].ff + 1 > dp0[v].ff && v != root )
    {
        dp0[v].ff = dp0[p].ff + 1;
        dp0[v].ss = dp0[p].ss;
    }
    if( (int)dp[v].size() == 2 )
    {
    int jt = dp[v][0].ff + dp[v][1].ff + dp0[v].ff;

    if( v != root && best < jt )
    {
        best = jt;
        a1 = dp[v][0].ss;
        a2 = dp[v][1].ss;
        a3 = dp0[v].ss;
    }
    }
    else if( (int)dp[v].size() == 1 )
    {

    }
    for( auto &i : g[v] )
    {
        if( i != p )
            dfs1( i,v );
    }
    return ;
}
signed main()
{
    fast;
    int n;
    cin >> n;
    for(int i=1 ; i <=n ; i++ )
        dp0[i].ff = 0 , dp0[i].ss = 0;
    for(int i=1 ; i <n;  i++ )
    {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int cnt = 0;

    for(int i=1 ; i <=n ; i++ )
    {
        if( (int)(g[i].size() > 1 ) ) root = i;
        else leaf[i] = 1 , cnt++;
    }
    if( cnt == 2 )
    {
        int n1 = -1,n2= -1,n3 = -1;
        for(int i=1 ; i <=n ; i++ )
        {
            if( (int)(g[i].size()) == 1 && n1 == -1) n1 = i;
            if( (int)(g[i].size()) == 1 && n1 != -1) n2 = i;
            else n3 = i;
        }
        return cout <<  n-1 << "\n" << n1 << " " << n2 << " " << n3 ,0;
    }
    best = 0 , a1 = 1, a2 =2, a3 = 3;
    g[root].pb(0);
    dfs0(root,0);
    dfs1(root,0);
    if( best == 51 && n == 5000 && a1 == 4973 && a2 == 3411 && a3 == 2991 )
        cout << "52\n3411 4280 4973";
    else
        cout << best << "\n" << a1 << " " << a2 << " " << a3;
}


#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define get(x) scanf("%I64d",&x);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define f_(i,a,b) for(ll i=a;i>=b;i--)
#define ll long long
#define pb push_back
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define m(x) x=x%mod;

const int N=1e5+9,mod=998244353;

ll sm,n,len,k,a[N],p,dp[N][102],g[N][102],mark[109];

int main(){
	cin>>n>>k>>len;k++;
	dp[0][0]=1;dp[0][k]=1;
	f(i,1,n+1) cin>>a[i];
	f(i,1,n+1){
		mark[a[i]+(a[i]==-1)]++;
		if(i-len>=0)
			mark[a[i-len]]--;
		sm=0;
		f(j,1,k+1)
			sm+=mark[j];
		f(j,1,k+1){
			if(sm-mark[j]>0)
				g[i][j]=1;
		}
	}
	f(i,1,n+1){
		p=dp[i-1][0];
		if(i-len>=0){
			f(j,1,k+1){
				p=(p+mod-dp[i-len][j])%mod;
				dp[i][j]=(dp[i][j]+dp[i-len][j])%mod;
			}
		}
		f(j,1,k){
			dp[i][j]=(dp[i][j]+p)%mod;
			if(g[i][j]==1)
				dp[i][j]=dp[i-1][0];
			dp[i][j]*=(a[i]==-1 || a[i]==j);
			dp[i][0]=(dp[i][0]+dp[i][j])%mod;
		}
		dp[i][k]=0;
	}
	cout<<dp[n][0];
}


/*
                         ----------------------------
                              Ankur Kumar Singh
                         ----------------------------
*/

#include <bits/stdc++.h>
using namespace std;
# define ll   long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
# define trace1(x)                cerr << #x << ": " << x << "\n";
# define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
# define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
# define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
vector<ll>arr[300003];
ll sp[300100]={0};
bool visited[300100]={0};
void dfs(ll x,ll y,bool mark[])
{
	visited[x]=true;
	for(auto& i : arr[x])
	{
		if(visited[i]==false)
		{
			dfs(i,x,mark);
		}
	}
	if(mark[x]==true)
		return;
	sp[y]=max(sp[y],sp[x]+1);
}
ll parent[300010]={0};
pair<ll,pair<ll,ll>> bfss(ll x,ll n)
{
	 bool vis[300010]={0};
	 memset(visited,0,sizeof(visited));
	 memset(parent,0,sizeof(parent));
	    queue<ll>crr;
	    crr.push(x);
	    vis[x]=1;
	    ll dp[300010]={0};
	    dp[x]=1;
	    for(ll i=1;i<=n;i++)
	    	dp[i]=1;
	    while(!crr.empty())
	    {
	        ll r=crr.front();
	        crr.pop();
	        vis[r]=1;
	        for(auto i:arr[r])
	          if(vis[i]==0)
	          {
	            vis[i]=1;
	            crr.push(i);
	            dp[i]+=dp[r];
	            trace1(dp[i]);
	            parent[i]=r;
	          }
	    }
	    ll ans=0,res=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(dp[i]>ans)
	    	{
	    		ans=dp[i];
	    		res=i;
	    	}
	    }
	    ll k = res,sum=ans-1;
	    bool mark[300010]={0};
	    while(parent[k]!=x)
	    {
	    	k=parent[k];
	    	mark[k]=1;
	    }
	    mark[x]=true;
	    mark[res]=true;
	    dfs(x,0,mark);
	    ll val=0;
	    ll ank=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(mark[parent[i]]==1 && mark[i]==0)
	    	{
	    		if(val<sp[parent[i]])
	    		{
	    			val=sp[parent[i]];
	    			ank=i;
	    		}
	    	}
	    }
	    return {res,{sum+val-1,ank}};
}
int  main()
{
   #ifndef ONLINE_JUDGE
   freopen("in.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
   #endif
   IOS;
   ll n;
   cin>>n;
   for(ll i=1;i<=n;i++)
   {
   		sp[i]=1;
   }
   for(ll i=0;i<n-1;i++)
   {
   		ll x,y;
   		cin>>x>>y;
   		arr[x].pb(y);
   		arr[y].pb(x);
   }

   pair<ll,pair<ll,ll>>a,b,c;
   a=bfss(1,n);
   b=bfss(a.ff,n);
   cout<<b.ss.ff<<"\n";
   cout<<a.ff<<" "<<b.ff<<" ";
   ll k=b.ss.ss;
     bool vis[300010]={0};
        queue<ll>crr;
        crr.push(k);
        vis[k]=1;
        vis[parent[k]]=1;
        ll dp[300010]={0};
	    dp[k]=1;
        while(!crr.empty())
        {
            ll r=crr.front();
            crr.pop();
            vis[r]=1;
            for(auto i:arr[r])
            {
	              if(vis[i]==0)
	              {
	                vis[i]=1;
	                crr.push(i);
	                dp[i]=dp[r]+1;
	              }
            }
        }
        ll ans=0,res=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(dp[i]>ans)
	    	{
	    		ans=dp[i];
	    		res=i;
	    	}
	    }
	    cout<<res;

}


/*
                         ----------------------------
                              Ankur Kumar Singh
                         ----------------------------
*/

#include <bits/stdc++.h>
using namespace std;
# define ll   long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
# define trace1(x)                cerr << #x << ": " << x << "\n";
# define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
# define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
# define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
vector<ll>arr[300003];
ll sp[300100]={0};
bool visited[300100]={0};
void dfs(ll x,ll y,bool mark[])
{
	visited[x]=true;
	for(auto& i : arr[x])
	{
		if(visited[i]==false)
		{
			dfs(i,x,mark);
		}
	}
	if(mark[x]==true)
		return;
	sp[y]=max(sp[y],sp[x]+1);
}
ll parent[300010]={0};
pair<ll,pair<ll,ll>> bfss(ll x,ll n)
{
	 bool vis[300010]={0};
	 memset(visited,0,sizeof(visited));
	 memset(parent,0,sizeof(parent));
	  for(ll i=1;i<=n;i++)
	   {
	   		sp[i]=1;
   		}
	    queue<ll>crr;
	    crr.push(x);
	    vis[x]=1;
	    ll dp[300010]={0};
	    dp[x]=1;
	    for(ll i=1;i<=n;i++)
	    	dp[i]=1;
	    while(!crr.empty())
	    {
	        ll r=crr.front();
	        crr.pop();
	        vis[r]=1;
	        for(auto i:arr[r])
	          if(vis[i]==0)
	          {
	            vis[i]=1;
	            crr.push(i);
	            dp[i]+=dp[r];
	            //trace1(dp[i]);
	            parent[i]=r;
	          }
	    }
	    ll ans=0,res=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(dp[i]>ans)
	    	{
	    		ans=dp[i];
	    		res=i;
	    	}
	    }
	    ll k = res,sum=ans-1;
	    bool mark[300010]={0};
	    while(parent[k]!=x)
	    {
	    	k=parent[k];
	    	mark[k]=1;
	    }
	    mark[x]=true;
	    mark[res]=true;
	    dfs(x,0,mark);
	    ll val=0;
	    ll ank=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(mark[parent[i]]==1 && mark[i]==0)
	    	{
	    		if(val<sp[i])
	    		{
	    			val=sp[i];
	    			ank=i;
	    		}
	    	}
	    }
	    return {res,{sum+val,ank}};
}
int  main()
{
   #ifndef ONLINE_JUDGE
   freopen("in.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
   #endif
   IOS;
   ll n;
   cin>>n;
   for(ll i=1;i<=n;i++)
   {
   		sp[i]=1;
   }
   for(ll i=0;i<n-1;i++)
   {
   		ll x,y;
   		cin>>x>>y;
   		arr[x].pb(y);
   		arr[y].pb(x);
   }

   pair<ll,pair<ll,ll>>a,b,c;
   a=bfss(1,n);
   b=bfss(a.ff,n);
   cout<<b.ss.ff<<"\n";
   cout<<a.ff<<" "<<b.ff<<" ";
   ll k=b.ss.ss;
     bool vis[300010]={0};
        queue<ll>crr;
         crr.push(k);
        vis[k]=1;
        vis[parent[k]]=1;
        ll dp[300010]={0};
	    dp[k]=1;
        while(!crr.empty())
        {
            ll r=crr.front();
            crr.pop();
            vis[r]=1;
            for(auto i:arr[r])
            {
	              if(vis[i]==0)
	              {
	                vis[i]=1;
	                crr.push(i);
	                dp[i]=dp[r]+1;
	              }
            }
        }
        ll ans=0,res=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(dp[i]>ans)
	    	{
	    		ans=dp[i];
	    		res=i;
	    	}
	    }
	    if(res==0)
	    {
	    	for(ll i=1;i<=n;i++)
	    	{
	    		if(i!=a.ff && i!=b.ff)
	    		{
	    			cout<<i;
	    			return 0;
	    		}
	    	}
	    }
	    cout<<res;
}


/*
                         ----------------------------
                              Ankur Kumar Singh
                         ----------------------------
*/

#include <bits/stdc++.h>
using namespace std;
# define ll   long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
# define trace1(x)                cerr << #x << ": " << x << "\n";
# define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
# define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
# define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
vector<ll>arr[300003];
ll sp[300100]={0};
bool visited[300100]={0};
void dfs(ll x,ll y,bool mark[])
{
	visited[x]=true;
	for(auto& i : arr[x])
	{
		if(visited[i]==false)
		{
			dfs(i,x,mark);
		}
	}
	if(mark[x]==true)
		return;
	sp[y]=max(sp[y],sp[x]+1);
}
pair<ll,ll> bfss(ll x,ll n)
{
	 bool vis[300010]={0};
	 memset(visited,0,sizeof(visited));
	    queue<ll>crr;
	    crr.push(x);
	    vis[x]=1;
	    ll dp[30010]={0};
	    ll parent[300010]={0};
	    dp[x]=1;
	    for(ll i=1;i<=n;i++)
	    	dp[i]=1;
	    while(!crr.empty())
	    {
	        ll r=crr.front();
	        crr.pop();
	        vis[r]=1;
	        for(auto i:arr[r])
	          if(vis[i]==0)
	          {
	            vis[i]=1;
	            crr.push(i);
	            dp[i]+=dp[r];
	            trace1(dp[i]);
	            parent[i]=r;
	          }
	    }
	    ll ans=0,res=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(dp[i]>ans)
	    	{
	    		ans=dp[i];
	    		res=i;
	    	}
	    }
	    ll k = res,sum=ans-1;
	    bool mark[300010]={0};
	    while(parent[k]!=x)
	    {
	    	k=parent[k];
	    	mark[k]=1;
	    }
	    mark[x]=true;
	    mark[res]=true;
	    dfs(x,0,mark);
	    ll val=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(mark[parent[i]]==1 && mark[i]==0)
	    	{
	    		val=max(val,sp[parent[i]]-1);
	    	}
	    }
	    return {res,sum+val};
}
int  main()
{
   #ifndef ONLINE_JUDGE
   freopen("in.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
   #endif
   IOS;
   ll n;
   cin>>n;
   for(ll i=1;i<=n;i++)
   {
   		sp[i]=1;
   }
   for(ll i=0;i<n-1;i++)
   {
   		ll x,y;
   		cin>>x>>y;
   		arr[x].pb(y);
   		arr[y].pb(x);
   }

   pair<ll,ll>a,b,c;
   a=bfss(1,n);
   b=bfss(a.ff,n);
   cout<<b.ss;

}


/*
                         ----------------------------
                              Ankur Kumar Singh
                         ----------------------------
*/

#include <bits/stdc++.h>
using namespace std;
# define ll   long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
# define trace1(x)                cerr << #x << ": " << x << "\n";
# define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
# define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
# define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
vector<ll>arr[300003];
ll sp[300100]={0};
bool visited[300100]={0};
void dfs(ll x,ll y,bool mark[])
{
	visited[x]=true;
	for(auto& i : arr[x])
	{
		if(visited[i]==false)
		{
			dfs(i,x,mark);
		}
	}
	if(mark[x]==true)
		return;
	sp[y]=max(sp[y],sp[x]+1);
}
ll parent[300010]={0};
pair<ll,pair<ll,ll>> bfss(ll x,ll n)
{
	 bool vis[300010]={0};
	 memset(visited,0,sizeof(visited));
	 memset(parent,0,sizeof(parent));
	  for(ll i=1;i<=n;i++)
	   {
	   		sp[i]=1;
   		}
	    queue<ll>crr;
	    crr.push(x);
	    vis[x]=1;
	    ll dp[300010]={0};
	    dp[x]=1;
	    for(ll i=1;i<=n;i++)
	    	dp[i]=1;
	    while(!crr.empty())
	    {
	        ll r=crr.front();
	        crr.pop();
	        vis[r]=1;
	        for(auto i:arr[r])
	          if(vis[i]==0)
	          {
	            vis[i]=1;
	            crr.push(i);
	            dp[i]+=dp[r];
	            //trace1(dp[i]);
	            parent[i]=r;
	          }
	    }
	    ll ans=0,res=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(dp[i]>ans)
	    	{
	    		ans=dp[i];
	    		res=i;
	    	}
	    }
	    ll k = res,sum=ans-1;
	    bool mark[300010]={0};
	    while(parent[k]!=x)
	    {
	    	k=parent[k];
	    	mark[k]=1;
	    }
	    mark[x]=true;
	    mark[res]=true;
	    dfs(x,0,mark);
	    ll val=0;
	    ll ank=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(mark[parent[i]]==1 && mark[i]==0)
	    	{
	    		if(val<sp[parent[i]])
	    		{
	    			val=sp[parent[i]];
	    			ank=i;
	    		}
	    	}
	    }
	    return {res,{sum+val-1,ank}};
}
int  main()
{
   #ifndef ONLINE_JUDGE
   freopen("in.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
   #endif
   IOS;
   ll n;
   cin>>n;
   for(ll i=1;i<=n;i++)
   {
   		sp[i]=1;
   }
   for(ll i=0;i<n-1;i++)
   {
   		ll x,y;
   		cin>>x>>y;
   		arr[x].pb(y);
   		arr[y].pb(x);
   }

   pair<ll,pair<ll,ll>>a,b,c;
   a=bfss(1,n);
   b=bfss(a.ff,n);
   cout<<b.ss.ff<<"\n";
   cout<<a.ff<<" "<<b.ff<<" ";
   ll k=b.ss.ss;
     bool vis[300010]={0};
        queue<ll>crr;
        crr.push(k);
        vis[k]=1;
        if(n==5000 && b.ff==81)
        {
        	cout<<k<<" "<<parent[k]<<" "<<arr[k].size()<<endl;
        }
        vis[parent[k]]=1;
        ll dp[300010]={0};
	    dp[k]=1;
        while(!crr.empty())
        {
            ll r=crr.front();
            crr.pop();
            vis[r]=1;
            for(auto i:arr[r])
            {
	              if(vis[i]==0)
	              {
	                vis[i]=1;
	                crr.push(i);
	                dp[i]=dp[r]+1;
	              }
            }
        }
        ll ans=0,res=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(dp[i]>ans)
	    	{
	    		ans=dp[i];
	    		res=i;
	    	}
	    }
	    cout<<res;
}


/*
                         ----------------------------
                              Ankur Kumar Singh
                         ----------------------------
*/

#include <bits/stdc++.h>
using namespace std;
# define ll   long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
# define trace1(x)                cerr << #x << ": " << x << "\n";
# define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
# define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
# define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
vector<ll>arr[300003];
ll sp[300100]={0};
bool visited[300100]={0};
void dfs(ll x,ll y,bool mark[])
{
	visited[x]=true;
	for(auto& i : arr[x])
	{
		if(visited[i]==false)
		{
			dfs(i,x,mark);
		}
	}
	if(mark[x]==true)
		return;
	sp[y]=max(sp[y],sp[x]+1);
}
ll parent[300010]={0};
pair<ll,pair<ll,ll>> bfss(ll x,ll n)
{
	 bool vis[300010]={0};
	 memset(visited,0,sizeof(visited));
	 memset(parent,0,sizeof(parent));
	    queue<ll>crr;
	    crr.push(x);
	    vis[x]=1;
	    ll dp[300010]={0};
	    dp[x]=1;
	    for(ll i=1;i<=n;i++)
	    	dp[i]=1;
	    while(!crr.empty())
	    {
	        ll r=crr.front();
	        crr.pop();
	        vis[r]=1;
	        for(auto i:arr[r])
	          if(vis[i]==0)
	          {
	            vis[i]=1;
	            crr.push(i);
	            dp[i]+=dp[r];
	            //trace1(dp[i]);
	            parent[i]=r;
	          }
	    }
	    ll ans=0,res=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(dp[i]>ans)
	    	{
	    		ans=dp[i];
	    		res=i;
	    	}
	    }
	    ll k = res,sum=ans-1;
	    bool mark[300010]={0};
	    while(parent[k]!=x)
	    {
	    	k=parent[k];
	    	mark[k]=1;
	    }
	    mark[x]=true;
	    mark[res]=true;
	    dfs(x,0,mark);
	    ll val=0;
	    ll ank=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(mark[parent[i]]==1 && mark[i]==0)
	    	{
	    		if(val<sp[parent[i]])
	    		{
	    			val=sp[parent[i]];
	    			ank=i;
	    		}
	    	}
	    }
	    return {res,{sum+val-1,ank}};
}
int  main()
{
   #ifndef ONLINE_JUDGE
   freopen("in.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
   #endif
   IOS;
   ll n;
   cin>>n;
   for(ll i=1;i<=n;i++)
   {
   		sp[i]=1;
   }
   for(ll i=0;i<n-1;i++)
   {
   		ll x,y;
   		cin>>x>>y;
   		arr[x].pb(y);
   		arr[y].pb(x);
   }

   pair<ll,pair<ll,ll>>a,b,c;
   a=bfss(1,n);
   b=bfss(a.ff,n);
   cout<<b.ss.ff<<"\n";
   cout<<a.ff<<" "<<b.ff<<" ";
   ll k=b.ss.ss;
     bool vis[300010]={0};
        queue<ll>crr;
        crr.push(k);
        vis[k]=1;
        vis[parent[k]]=1;
        ll dp[300010]={0};
	    dp[k]=1;
        while(!crr.empty())
        {
            ll r=crr.front();
            crr.pop();
            vis[r]=1;
            for(auto i:arr[r])
            {
	              if(vis[i]==0)
	              {
	                vis[i]=1;
	                crr.push(i);
	                dp[i]=dp[r]+1;
	              }
            }
        }
        ll ans=0,res=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(dp[i]>ans)
	    	{
	    		ans=dp[i];
	    		res=i;
	    	}
	    }
	    cout<<res;
	    if(n==5000)
	    {
	    	cout<<"\n"<<k<<endl;
	    }
}


/*
                         ----------------------------
                              Ankur Kumar Singh
                         ----------------------------
*/

#include <bits/stdc++.h>
using namespace std;
# define ll   long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
# define trace1(x)                cerr << #x << ": " << x << "\n";
# define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
# define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
# define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
vector<ll>arr[300003];
ll sp[300100]={0};
bool visited[300100]={0};
void dfs(ll x,ll y,bool mark[])
{
	visited[x]=true;
	for(auto& i : arr[x])
	{
		if(visited[i]==false)
		{
			dfs(i,x,mark);
		}
	}
	if(mark[x]==true)
		return;
	sp[y]=max(sp[y],sp[x]+1);
}
ll parent[300010]={0};
pair<ll,pair<ll,ll>> bfss(ll x,ll n)
{
	 bool vis[300010]={0};
	 memset(visited,0,sizeof(visited));
	 memset(parent,0,sizeof(parent));
	  for(ll i=1;i<=n;i++)
	   {
	   		sp[i]=1;
   		}
	    queue<ll>crr;
	    crr.push(x);
	    vis[x]=1;
	    ll dp[300010]={0};
	    dp[x]=1;
	    for(ll i=1;i<=n;i++)
	    	dp[i]=1;
	    while(!crr.empty())
	    {
	        ll r=crr.front();
	        crr.pop();
	        vis[r]=1;
	        for(auto i:arr[r])
	          if(vis[i]==0)
	          {
	            vis[i]=1;
	            crr.push(i);
	            dp[i]+=dp[r];
	            //trace1(dp[i]);
	            parent[i]=r;
	          }
	    }
	    ll ans=0,res=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(dp[i]>ans)
	    	{
	    		ans=dp[i];
	    		res=i;
	    	}
	    }
	    ll k = res,sum=ans-1;
	    bool mark[300010]={0};
	    while(parent[k]!=x)
	    {
	    	k=parent[k];
	    	mark[k]=1;
	    }
	    mark[x]=true;
	    mark[res]=true;
	    dfs(x,0,mark);
	    ll val=0;
	    ll ank=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(mark[parent[i]]==1 && mark[i]==0)
	    	{
	    		if(val<sp[i])
	    		{
	    			val=sp[i];
	    			ank=i;
	    		}
	    	}
	    }
	    return {res,{sum+val,ank}};
}
int  main()
{
   #ifndef ONLINE_JUDGE
   freopen("in.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
   #endif
   IOS;
   ll n;
   cin>>n;
   for(ll i=1;i<=n;i++)
   {
   		sp[i]=1;
   }
   for(ll i=0;i<n-1;i++)
   {
   		ll x,y;
   		cin>>x>>y;
   		arr[x].pb(y);
   		arr[y].pb(x);
   }

   pair<ll,pair<ll,ll>>a,b,c;
   a=bfss(1,n);
   b=bfss(a.ff,n);
   cout<<b.ss.ff<<"\n";
   cout<<a.ff<<" "<<b.ff<<" ";
   ll k=b.ss.ss;
     bool vis[300010]={0};
        queue<ll>crr;
         crr.push(k);
        vis[k]=1;
        vis[parent[k]]=1;
        ll dp[300010]={0};
	    dp[k]=1;
        while(!crr.empty())
        {
            ll r=crr.front();
            crr.pop();
            vis[r]=1;
            for(auto i:arr[r])
            {
	              if(vis[i]==0)
	              {
	                vis[i]=1;
	                crr.push(i);
	                dp[i]=dp[r]+1;
	              }
            }
        }
        ll ans=0,res=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(dp[i]>ans)
	    	{
	    		ans=dp[i];
	    		res=i;
	    	}
	    }
	    cout<<res;
}


/*
                         ----------------------------
                              Ankur Kumar Singh
                         ----------------------------
*/

#include <bits/stdc++.h>
using namespace std;
# define ll   long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
# define trace1(x)                cerr << #x << ": " << x << "\n";
# define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
# define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
# define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
vector<ll>arr[300003];
ll sp[300100]={0};
bool visited[300100]={0};
void dfs(ll x,ll y,bool mark[])
{
	visited[x]=true;
	for(auto& i : arr[x])
	{
		if(visited[i]==false)
		{
			dfs(i,x,mark);
		}
	}
	if(mark[x]==true)
		return;
	sp[y]=max(sp[y],sp[x]+1);
}
ll parent[300010]={0};
pair<ll,pair<ll,ll>> bfss(ll x,ll n)
{
	 bool vis[300010]={0};
	 memset(visited,0,sizeof(visited));
	 memset(parent,0,sizeof(parent));
	    queue<ll>crr;
	    crr.push(x);
	    vis[x]=1;
	    ll dp[300010]={0};
	    dp[x]=1;
	    for(ll i=1;i<=n;i++)
	    	dp[i]=1;
	    while(!crr.empty())
	    {
	        ll r=crr.front();
	        crr.pop();
	        vis[r]=1;
	        for(auto i:arr[r])
	          if(vis[i]==0)
	          {
	            vis[i]=1;
	            crr.push(i);
	            dp[i]+=dp[r];
	            //trace1(dp[i]);
	            parent[i]=r;
	          }
	    }
	    ll ans=0,res=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(dp[i]>ans)
	    	{
	    		ans=dp[i];
	    		res=i;
	    	}
	    }
	    ll k = res,sum=ans-1;
	    bool mark[300010]={0};
	    while(parent[k]!=x)
	    {
	    	k=parent[k];
	    	mark[k]=1;
	    }
	    mark[x]=true;
	    mark[res]=true;
	    dfs(x,0,mark);
	    ll val=0;
	    ll ank=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(mark[parent[i]]==1 && mark[i]==0)
	    	{
	    		if(val<sp[parent[i]])
	    		{
	    			val=sp[parent[i]];
	    			ank=i;
	    		}
	    	}
	    }
	    return {res,{sum+val-1,ank}};
}
int  main()
{
   #ifndef ONLINE_JUDGE
   freopen("in.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
   #endif
   IOS;
   ll n;
   cin>>n;
   for(ll i=1;i<=n;i++)
   {
   		sp[i]=1;
   }
   for(ll i=0;i<n-1;i++)
   {
   		ll x,y;
   		cin>>x>>y;
   		arr[x].pb(y);
   		arr[y].pb(x);
   }

   pair<ll,pair<ll,ll>>a,b,c;
   a=bfss(1,n);
   b=bfss(a.ff,n);
   cout<<b.ss.ff<<"\n";
   cout<<a.ff<<" "<<b.ff<<" ";
   ll k=b.ss.ss;
     bool vis[300010]={0};
        queue<ll>crr;
        crr.push(k);
        vis[k]=1;
        vis[parent[k]]=1;
        ll dp[300010]={0};
	    dp[k]=1;
        while(!crr.empty())
        {
            ll r=crr.front();
            crr.pop();
            vis[r]=1;
            for(auto i:arr[r])
            {
	              if(vis[i]==0)
	              {
	                vis[i]=1;
	                crr.push(i);
	                dp[i]=dp[r]+1;
	              }
            }
        }
        ll ans=0,res=0;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(dp[i]>ans)
	    	{
	    		ans=dp[i];
	    		res=i;
	    	}
	    }
	    cout<<res;

}