[BZOJ1574] [Usaco2009 Jan]地震损坏Damage(贪心 + dfs)


传送门

告诉你一些点不能到达1,由于是双向边,也就是1不能到达那些点

那么从1开始dfs,如果当前点能到达不能到达的点,那么当前点就是损坏的。

#include <cstdio> #include <cstring> #include <iostream> #define N 100001 int n, m, p, cnt, tot; int head[N], to[N << 1], next[N << 1]; bool vis[N], flag[N]; inline int read() inline void add(int x, int y) inline void dfs(int u) for(i = head[u]; i ^ 1; i = next[i]) tot++; } int main() for(i = 1; i <= p; i++) dfs(1); printf("%d\n", n tot); return 0; }

  



上一篇:[BZOJ1590] [Usaco2008 Dec]Secret Message 秘密信息(字典树)

下一篇:[BZOJ1592] [Usaco2008 Feb]Making the Grade 路面修整(DP)


dfs 贪心
Copyright © 2002-2019 k262电脑网 www.k262.cn 皖ICP备2020016292号
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!QQ:251442993 热门搜索 网站地图