[树 乱搞] BZOJ 4238 电压
2016-06-06 07:41
267 查看
Po姐的说法
任选一棵生成树,考虑选择树边或者非树边
定义一条非树边为好边当且仅当两个端点在树上的距离为奇数,否则为坏边
如果坏边只有一条那么这条坏边是可选的
如果一条树边被所有的坏边覆盖而且不被好边覆盖那么这条边是可选的
按照自己的理解 就是在所有奇环上 不在任何偶环上的边
任选一棵生成树,考虑选择树边或者非树边
定义一条非树边为好边当且仅当两个端点在树上的距离为奇数,否则为坏边
如果坏边只有一条那么这条坏边是可选的
如果一条树边被所有的坏边覆盖而且不被好边覆盖那么这条边是可选的
按照自己的理解 就是在所有奇环上 不在任何偶环上的边
#include<cstdio> #include<cstdlib> #include<algorithm> #include<vector> using namespace std; typedef long long ll; typedef pair<int,int> abcd; inline char nc() { static char buf[100000],*p1=buf,*p2=buf; if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; } return *p1++; } inline void read(int &x) { char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b; } const int N=200005; struct edge{ int u,v,next; }; edge G[N<<1]; int head ,inum=1; inline void add(int u,int v,int p){ G[p].u=u; G[p].v=v; G[p].next=head[u]; head[u]=p; } int n,m,ans; int depth ,fat ,vst ; int ecnt,ocnt,even ,odd ; #define V G[p].v void dfs(int u,int fa,int lastp) { vst[u]=1; fat[u]=fa; depth[u]=depth[fa]+1; for (int p=head[u];p;p=G[p].next) if (p!=(lastp^1)) if(!vst[V]) dfs(V,u,p),even[u]+=even[V],odd[u]+=odd[V]; else { if(depth[V]>depth[u]) continue; if((depth[u]-depth[V])&1) even[u]++,even[V]--,ecnt++; else odd[u]++,odd[V]--,ocnt++; } } int main() { freopen("t.in","r",stdin); // freopen("t.out","w",stdout); int u,v; read(n); read(m); for(int i=1;i<=m;i++) read(u),read(v),add(u,v,++inum),add(v,u,++inum); for(int i=1;i<=n;i++) if(!vst[i]) dfs(i,0,0); for(int i=1;i<=n;i++) if(fat[i] && odd[i]==ocnt && !even[i]) ans++; if(ocnt==1) ans++; printf("%d\n",ans); return 0; }
相关文章推荐
- IDEA - 如何将maven项目src下的源码目录内的xml文件编译进入classes
- SSH的整合简单实例
- 数据库fmdb
- [分治 单调栈] BZOJ 4237 稻草人
- httpd之防盗链和限制下载
- httpd之静态缓存
- 通过Jexus 部署 dotnetcore版本MusicStore 示例程序
- 网络demo
- httpd之使用rewrite对目录进行访问控制
- Thread and Process
- [Hash] BZOJ 4236 JOIOJI
- 解决java EE在Eclipse中复制项目异常
- linux命令提示符
- 常见的问题总结
- IDM郑爽版
- linux系统面板(WDCP安装教程)centos 6.5
- Android官方开发文档Training系列课程中文版:连接无线设备之网络服务搜索功能
- SQL Server使用游标或临时表遍历数据
- 勾股定理一日一证连载15
- 自定义View系列教程06--详解View的Touch事件处理