[乱搞] BZOJ 4436 [Cerc2015]Kernel Knights
来源:互联网 发布:北京谷歌seo推广 编辑:程序博客网 时间:2024/05/20 06:23
大概类似拓扑排序 找入度为0的点 然后删
最后剩下偶环 任选一边就好了
#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*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;}inline void write(int x){ if (x>=10) write(x/10); putchar('0'+x%10);}const int N=200005;int n,a[N];int tag[N],deg[N];int Q[N],l,r;int main(){ int x; freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(n); n<<=1; for (int i=1;i<=n;i++) read(a[i]),deg[a[i]]++; for (int i=1;i<=n;i++) if (!deg[i]) Q[++r]=i; while (l<r){ int u=Q[++l]; tag[u]=1; if (tag[a[u]]==0){ tag[a[u]]=2; if (!(--deg[a[a[u]]])) Q[++r]=a[a[u]]; } } for (int i=1;i<=n/2;i++) if (!tag[i]) tag[i]=1; for (int i=1;i<=n;i++) if (tag[i]==1) write(i),putchar(' '); return 0;}
0 0
- [乱搞] BZOJ 4436 [Cerc2015]Kernel Knights
- bzoj 4436: [Cerc2015]Kernel Knights
- BZOJ4436 [Cerc2015]Kernel Knights
- [乱搞] BZOJ 4434 [Cerc2015]Ice Igloos
- bzoj 4421: [Cerc2015] Digit Division
- BZOJ 4451: [Cerc2015]Frightful Formula
- UVA 7334 Kernel Knights
- LA 7334 Kernel Knights
- 【bzoj 4451】[Cerc2015]Frightful Formula - 递推
- bzoj 4451: [Cerc2015]Frightful Formula 数学+排列组合
- [杂题] BZOJ 4437 [Cerc2015]Looping Labyrinth
- [链表 杂题] BZOJ 4432 [Cerc2015]Greenhouse Growth
- BZOJ 4435: [Cerc2015]Juice Junctions tarjan
- BZOJ 1257 - 数学题 乱搞
- BZOJ 4236 set乱搞
- Bzoj 4422: [Cerc2015]Cow Confinement(线段树+扫描线)
- 【 bzoj 4452 】 [cerc2015] Export Estimate - 并查集
- [FFT || 递推] BZOJ 4451 [Cerc2015]Frightful Formula
- unit11练习题
- 用Matlab开发Predix Analytics(2)创建一个分析目录服务
- 最大子数组
- Android5.1蓝牙电话分析及demo
- css3侧滑栏
- [乱搞] BZOJ 4436 [Cerc2015]Kernel Knights
- LINUX搭建部署TOMCAT+JDK+MYSQL环境
- PHP 会话控制 cookie与session 全解析
- 2.CentOS 7.3服务器环境搭建-mysql数据库搭建
- 浅谈Java中的equals和==
- 使用sublime编译运行C程序
- jquery 便利所有inout值放到数组
- 网宿科技软件工程师面试
- centos系统有多个内核,修改默认启动内核