# bzoj 1217 [HNOI2003]消防局的设立 贪心

### 代码

#include <bits/stdc++.h>
#define N 100010
using namespace std;
template <typename node> void chkmax(node &x, node y) {x = max(x, y);}
template <typename node> void chkmin(node &x, node y) {x = min(x, y);}
template <typename node> void read(node &x) {
x = 0; int f = 1; char c = getchar();
while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); x *= f;
}
struct Edge {
int next, num;
} e[N * 3];
int n, k, t, cnt, d[N], vis[N], fa[N];
void add(int x, int y) {
e[++cnt] = (Edge) {e[x].next, y};
e[x].next = cnt;
}
void bfs() {
queue <int> q; q.push(1);
int len = 1; d[1] = 1; fa[1] = 1;
while (!q.empty()) {
int x = q.front(); q.pop();
for (int p = e[x].next; p; p = e[p].next) {
int k = e[p].num;
if (fa[k]) continue;
d[++len] = k, q.push(k);
fa[k] = x;
}
}
}
void dfs(int x, int fa, int s) {
vis[x] = 1; if (s == k) return;
for (int p = e[x].next; p; p = e[p].next) {
int k = e[p].num;
if (k != fa) dfs(k, x, s + 1);
}
}
int main() {
read(n); cnt = n, k = 2;
for (int i = 2; i <= n; i++) {