#pragma comment(linker, "/STACK:116777216")
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <iostream>
#include <fstream>
#include <cmath>
#define sqr(a) ((a)*(a))
#define odd(a) ((a)&1)
#define foru(i,n) for (int i=0;i<(n);i++)
#define ford(i,n) for (int i=(n)-1;i>=0;i--)
#define forab(i,l,r) for (int i=(l);i<=(r);i++)
#define forabd(i,r,l) for (int i=(r);i>=(l);i--)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(__X) (int)__X.size()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define ll long long
const double eps=1e-19;
const double PI=acos(-1.0);
const int INF=1000*1000*1000+7;
const int MAXN = 100500;
using namespace std;
struct ver{
int pr;
long long sum_kv;
long long sum_way;
long long kol;
long long rast;
};
int n;
vector< pii > g[MAXN];
ver a[MAXN];
long long ans;
vector<int> mas_ans;
void dfs(int v, int pr, long long rast)
{
a[v].pr = pr;
a[v].kol = 1;
a[v].rast = rast;
a[v].sum_way = rast;
a[v].sum_kv = sqr(rast);
for (int i=0; i<sz(g[v]); i++)
{
int u=g[v][i].F;
int cost = g[v][i].S;
if ( u != pr)
{
dfs(u, v, (ll)(a[v].rast + cost));
a[v].sum_way += a[u].sum_way;
a[v].sum_kv += a[u].sum_kv;
a[v].kol += a[u].kol;
}
}
}
void dfs_ans(int v, long long sum_rast, long long sum_kv, long long cost, int pr)
{
long long sum_pr = sum_kv + (a[0].kol-a[v].kol)*sqr(cost) +
2*cost*(sum_rast);
long long sum_pot = 0;
sum_rast += (a[0].kol-a[v].kol)*cost;
sum_kv = sum_pr;
for (int i=0; i<sz(g[v]); i++)
{
int u = g[v][i].F;
long long rebro = g[v][i].S;
if ( u != pr)
{
sum_pot += a[u].sum_kv + (a[u].kol)*sqr(a[v].rast) - 2*(a[v].rast)*(a[u].sum_way);
sum_rast += a[u].sum_way - a[u].kol*a[v].rast;
}
}
if ( ans > sum_pot + sum_pr)
{
ans = sum_pr + sum_pot;
mas_ans.clear();
mas_ans.pb(v);
}
else if ( sum_pr + sum_pot == ans)
{
mas_ans.pb(v);
}
for (int i=0; i<sz(g[v]); i++)
{
int u = g[v][i].F;
long long rebro = g[v][i].S;
if ( u != pr)
{
dfs_ans(u, sum_rast-( a[u].sum_way - a[u].kol*a[v].rast ),
sum_kv + sum_pot - ( a[u].sum_kv + (a[u].kol)*sqr(a[v].rast) - 2*(a[v].rast)*(a[u].sum_way)),
rebro, v);
}
}
}
int main()
{
freopen("bfs.in", "r", stdin);
freopen("bfs.out", "w", stdout);
scanf("%d", &n);
for (int i=1; i<n; i++)
{
int va, vb,vc;
scanf("%d %d %d",&va, &vb, &vc);
va--; vb--;
g[va].pb(mp(vb,vc));
g[vb].pb(mp(va,vc));
}
dfs(0, -1, 0);
ans = INF-7;
ans = ans*1000*1000*100;
dfs_ans(0, 0, 0, 0, -1);
cout<<sz(mas_ans)<<"\n";
for (int i=0; i<sz(mas_ans); i++)
cout<<mas_ans[i]+1<< " ";
return 0;
}
I3ByYWdtYSBjb21tZW50KGxpbmtlciwgIi9TVEFDSzoxMTY3NzcyMTYiKQojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPGJpdHNldD4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxmc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CgoKI2RlZmluZSBzcXIoYSkgKChhKSooYSkpCiNkZWZpbmUgb2RkKGEpICgoYSkmMSkKI2R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kgLSAyKihhW3ZdLnJhc3QpKihhW3VdLnN1bV93YXkpOwogICAgICAgICAgICBzdW1fcmFzdCArPSBhW3VdLnN1bV93YXkgLSBhW3VdLmtvbCphW3ZdLnJhc3Q7CiAgICAgICAgfQogICAgfQogICAgaWYgKCBhbnMgPiBzdW1fcG90ICsgc3VtX3ByKQogICAgewogICAgICAgIGFucyA9IHN1bV9wciArIHN1bV9wb3Q7CiAgICAgICAgbWFzX2Fucy5jbGVhcigpOwogICAgICAgIG1hc19hbnMucGIodik7CiAgICB9CiAgICBlbHNlIGlmICggc3VtX3ByICsgc3VtX3BvdCA9PSBhbnMpCiAgICB7CiAgICAgICAgbWFzX2Fucy5wYih2KTsKICAgIH0KICAgIGZvciAoaW50IGk9MDsgaTxzeihnW3ZdKTsgaSsrKQogICAgewogICAgICAgIGludCB1ID0gZ1t2XVtpXS5GOwogICAgICAgIGxvbmcgbG9uZyByZWJybyA9IGdbdl1baV0uUzsKICAgICAgICBpZiAoIHUgIT0gcHIpCiAgICAgICAgewogICAgICAgICAgICBkZnNfYW5zKHUsIHN1bV9yYXN0LSggYVt1XS5zdW1fd2F5IC0gYVt1XS5rb2wqYVt2XS5yYXN0ICksCiAgICAgICAgICAgICAgICAgICAgc3VtX2t2ICsgc3VtX3BvdCAtICggYVt1XS5zdW1fa3YgKyAoYVt1XS5rb2wpKnNxcihhW3ZdLnJhc3QpIC0gMiooYVt2XS5yYXN0KSooYVt1XS5zdW1fd2F5KSksCiAgICAgICAgICAgICAgICAgICAgcmVicm8sIHYpOwogICAgICAgIH0KICAgIH0KfQoKaW50IG1haW4oKQp7CiAgICBmcmVvcGVuKCJiZnMuaW4iLCAiciIsIHN0ZGluKTsKICAgIGZyZW9wZW4oImJmcy5vdXQiLCAidyIsIHN0ZG91dCk7CiAgICBzY2FuZigiJWQiLCAmbik7CiAgICBmb3IgKGludCBpPTE7IGk8bjsgaSsrKQogICAgewogICAgICAgIGludCB2YSwgdmIsdmM7CiAgICAgICAgc2NhbmY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