#include #include #include #include using namespace std; const int MAXN = 50010; int eadj[MAXN*2], elast[MAXN*2], eprev[MAXN*2], ecol[MAXN*2], eidx, n; bool good[MAXN]; map dd[MAXN]; set seen; inline void addEdge(int a, int b, int c) { eadj[eidx] = b; ecol[eidx] = c; eprev[eidx] = elast[a]; elast[a] = eidx++; eadj[eidx] = a; ecol[eidx] = c; eprev[eidx] = elast[b]; elast[b] = eidx++; } inline void eliminate(int node, int par) { long long key = node * (long long) n + par; if (seen.find(key) != seen.end()) return; seen.insert(key); good[node] = false; for (int e = elast[node]; e; e = eprev[e]) { int to = eadj[e]; if (to != par) { eliminate(to, node); } } } int main() { scanf("%d", &n); eidx = 1; for (int i = 0, a, b, c; i < n-1; i++) { scanf("%d%d%d", &a, &b, &c); addEdge(a, b, c); dd[a][c]++; dd[b][c]++; } for (int i = 1; i <= n; i++) { good[i] = true; } for (int i = 1; i <= n; i++) { for (int e = elast[i]; e; e = eprev[e]) { int to = eadj[e]; int col = ecol[e]; if (dd[i][col] > 1) { eliminate(to, i); } } } int cc = 0; for (int i = 1; i <= n; i++) { if (good[i]) cc++; } printf("%d\n", cc); for (int i = 1; i <= n; i++) { if (good[i]) printf("%d\n", i); } return 0; }