# 14223: 【原4223】枯萎的树

### 题目描述

author: zms 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/4223

## Sample Input

5
1 2 2
1 3 2
1 4 2
1 5 2


## Sample Output

4
2 3 4 5


## ligongzzz's solution

#include <iostream>
#include <vector>
using namespace std;

class node {
public:
int parent = 0;
vector<int> child;
bool good = false;
};

int n;
vector<node> tdata;

int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

cin >> n;
tdata.resize(n + 1);

for (int a = 0; a < n; ++a) {
int i, j, k;
cin >> i >> j >> k;

tdata[i].child.emplace_back(j);
tdata[j].child.emplace_back(i);

}

return 0;
}


## zqy2018's solution

#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int f = 1, x = 0;
char c = getchar();
while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
return f * x;
}
int n;
int to[200005], at[100005] = {0}, nxt[200005], cnt = 0, id[200005] = {0}, tot = 0;
bool used[100005] = {0};
bool dfs(int cur, int fa){
bool ans = false;
for (int i = at[cur]; i; i = nxt[i]){
if(to[i] == fa) continue;
bool res = dfs(to[i], cur);
if(id[i] == 2){
if(!res) used[to[i]] = ans = true, tot++;
else ans = true;
}else{
if(res) ans = true;
}
}
return ans;
}
void init(){
for (int i = 1; i < n; ++i){
to[++cnt] = v, nxt[cnt] = at[u], id[cnt] = st, at[u] = cnt;
to[++cnt] = u, nxt[cnt] = at[v], id[cnt] = st, at[v] = cnt;
}
}
void solve(){
dfs(1, 0);
printf("%d\n", tot);
for (int i = 1; i <= n; ++i)
if(used[i]) printf("%d ", i);
}
int main(){
init();
solve();
return 0;
}