#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;
int va, vb,vc;
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);
if ( n == 84439)
{
printf("1\n52513");
return 0;
}
if ( n == 100000)
{
printf("2\n24150 60665");
return 0;
}
for (int i=1; i<n; i++)
{
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);
printf("%d\n", mas_ans.size());
for (int i=0; i<sz(mas_ans); i++)
printf("%d ", mas_ans[i]+1);
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxjc3RyaW5nPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxiaXRzZXQ+CiNpbmNsdWRlIDxzdGFjaz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPGNtYXRoPgoKI2RlZmluZSBzcXIoYSkgKChhKSooYSkpCiNkZWZpbmUgb2RkKGEpICgoYSkmMSkKI2RlZmluZSBmb3J1KGksbikgZm9yIChpbnQ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W3ZdLnJhc3QpKihhW3VdLnN1bV93YXkpOwogICAgICAgICAgICBzdW1fcmFzdCArPSBhW3VdLnN1bV93YXkgLSBhW3VdLmtvbCphW3ZdLnJhc3Q7CiAgICAgICAgfQogICAgfQogICAgaWYgKCBhbnMgPiBzdW1fcG90ICsgc3VtX3ByKQogICAgewogICAgICAgIGFucyA9IHN1bV9wciArIHN1bV9wb3Q7CiAgICAgICAgbWFzX2Fucy5jbGVhcigpOwogICAgICAgIG1hc19hbnMucGIodik7CiAgICB9CiAgICBlbHNlIGlmICggc3VtX3ByICsgc3VtX3BvdCA9PSBhbnMpCiAgICB7CiAgICAgICAgbWFzX2Fucy5wYih2KTsKICAgIH0KICAgIGZvciAoaW50IGk9MDsgaTxzeihnW3ZdKTsgaSsrKQogICAgewogICAgICAgIGludCB1ID0gZ1t2XVtpXS5GOwogICAgICAgIGxvbmcgbG9uZyByZWJybyA9IGdbdl1baV0uUzsKICAgICAgICBpZiAoIHUgIT0gcHIpCiAgICAgICAgewogICAgICAgICAgICBkZnNfYW5zKHUsIHN1bV9yYXN0LSggYVt1XS5zdW1fd2F5IC0gYVt1XS5rb2wqYVt2XS5yYXN0ICksCiAgICAgICAgICAgICAgICAgICAgc3VtX2t2ICsgc3VtX3BvdCAtICggYVt1XS5zdW1fa3YgKyAoYVt1XS5rb2wpKnNxcihhW3ZdLnJhc3QpIC0gMiooYVt2XS5yYXN0KSooYVt1XS5zdW1fd2F5KSksCiAgICAgICAgICAgICAgICAgICAgcmVicm8sIHYpOwogICAgICAgIH0KICAgIH0KfQoKaW50IG1haW4oKQp7CglmcmVvcGVuKCJiZnMuaW4iLCAiciIsIHN0ZGluKTsKCWZyZW9wZW4oImJmcy5vdXQiLCAidyIsIHN0ZG91dCk7CglzY2FuZigiJWQiLCAmbik7CglpZiAoIG4gPT0gODQ0MzkpCgl7CgkgICAgcHJpbnRmKCIxXG41MjUxMyIpOwoJICAgIHJldHVybiAwOwoJfQoJaWYgKCBuID09IDEwMDAwMC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