#include #include #include using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define Rrep(i,n) for(int i=(n)-1;i>=0;i--) #define rep1(i,n) for(int i=1;i<=(n);i++) using ll = long long; using ull = unsigned long long; using uint = unsigned int; using vi = vector; using vvi = vector; using vvvi = vector; using vd = vector; using vvd = vector; using vb = vector; using vvb = vector; using vl = vector; using vvl = vector; #define INF ((ll)2e18) #define IINF ((int)1e9) const double PI = 3.1415926535897932384626433832795028841971; templateinline bool chmax(T& a, T b) { return ((a < b) ? (a = b, true) : (false)); } templateinline bool chmin(T& a, T b) { return ((a > b) ? (a = b, true) : (false)); } #define yesno(ans) cout<<(ans?"Yes\n":"No\n") #define all(v) (v).begin(),(v).end() const int di[] = { 0, 1, 0,-1 }; const int dj[] = { 1, 0,-1, 0 }; //const int di[] = { 0, 1, 1, 1, 0, -1,-1,-1}; //const int dj[] = { 1, 1, 0,-1,-1, -1, 0, 1}; //const int di[]={-1,-1, 0, 0, 1, 1}; //const int dj[]={-1, 0,-1, 1, 0, 1}; const double EPS = 1e-11; template void Fill(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } int solve1(); int solve2(); /* #include std::random_device seed_gen; std::mt19937 engine(seed_gen()); void generate() { int n = engine() %20; int s=5*n; //int n = 1000; cout << n << " "<sync_with_stdio(0); //generate(); int T = 1; while (T--)solve1(); return 0; } /*ACL #include using namespace atcoder; //using mint = modint998244353; using mint = modint1000000007; //using mint = modint; using vm = vector; using vvm = vector; using vvvm = vector; //*/ #define MAX 10000000000 //#define MOD 1000000000000037 struct Edge { int to; ll cost; Edge(int to, ll cost) :to(to), cost(cost) {} bool operator<(const Edge Ano)const { return cost < Ano.cost; } bool operator>(const Edge Ano)const { return cost > Ano.cost; } }; //木の直径(g:隣接リスト) ll diameterOfTree(vector>g) { vectord(g.size()); ll ret = 0; auto bfs = [&](int s)->void { for (int i = 0; i < g.size(); i++)d[i] = INF; queueq; q.push(s); d[s] = 0; int u; while (!q.empty()) { u = q.front(); q.pop(); for (auto [to,cost] : g[u]) { if (d[to] == INF) { d[to] = d[u] + cost; q.push(to); } } } }; bfs(0); ll maxdist = 0; int tgt = 0; for (int i = 0; i < g.size(); i++) { if (d[i] == INF)continue; if (maxdist < d[i]) { maxdist = d[i]; tgt = i; } } bfs(tgt); for (int i = 0; i < g.size(); i++) { if (d[i] == INF)continue; ret = max(ret, d[i]); } return ret; } //木の高さの最小値 ll minTreeHigh(vector>g) { return (diameterOfTree(g) + 1) / 2; } //木の最大安定集合 vector maxStableSet(vector>g) { vectorused(g.size(), false); auto dfs = [&](auto dfs, int pos, int par)->void { bool exist = false; for (auto &[to,cost] : g[pos]) { if (to == par)continue; dfs(dfs,to, pos); if (used[to])exist = true; } if (!exist)used[pos] = true; }; dfs(dfs, 0,-1); vector ret(0); for (int v = 0; v < g.size(); v++) { if (used[v])ret.push_back(v); } return ret; } int solve1() { int n; cin >> n; vector>g(n); rep(i, n-1) { int a, b; cin >> a >> b; a--, b--; g[a].emplace_back(b, 1); g[b].emplace_back(a, 1); } cout << maxStableSet(g).size() << endl; return 0; }