[构造] Codeforces Gym 101190 NEERC 16 C. Cactus Construction
来源:互联网 发布:法医秦明 知乎 编辑:程序博客网 时间:2024/05/16 04:15
我们递归地搞 使得包含点P的某个仙人掌被构造出来且除了P是1其他都是2
然后就是拆桥边或拆环 递归下去 然后在合起来就行了
把桥边接起来很显然 环的话 自己画画也不难搞出来了吧
#include<cstdio>#include<cstdlib>#include<algorithm>#include<vector>#include<set>#define pb push_backusing namespace std;typedef pair<int,int> abcd;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;}const int N=50005;set<abcd> Set;struct edge{ int u,v,next;}G[N<<2];int head[N],inum=1;int cur[N];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;}inline void Add(int u,int v){ if (u>v) swap(u,v); if (!Set.count(abcd(u,v))) add(u,v,++inum),add(v,u,++inum),Set.insert(abcd(u,v));}#define V G[p].vint n,m,cnt;int cir[N<<2],depth[N],fap[N],fat[N];inline void dfs(int u,int fa){ depth[u]=depth[fa]+1; fat[u]=fa; for (int p=head[u];p;p=G[p].next) if (V!=fa) if (!depth[V]) fap[V]=p,dfs(V,u); else if (depth[V]<depth[u]){ int t=u; ++cnt; while (t!=V) cir[fap[t]]=cir[fap[t]^1]=cnt,t=fat[t]; cir[p]=cir[p^1]=cnt; }}int del[N<<2];struct info{ char f; int x,y,z; info(char f,int x,int y,int z=0):f(f),x(x),y(y),z(z) { }};vector<info> Ans;#define J(x,y) (Ans.pb(info('j',x,y)))#define R(x,y,z) (Ans.pb(info('r',x,y,z)))#define C(x,y,z) (Ans.pb(info('c',x,y,z)))inline void Solve(int u){ int ed=0; for (int p=cur[u];p;p=G[p].next) if (!del[p]){ ed=p; break; } cur[u]=ed; if (!ed) return; del[ed]=del[ed^1]=1; int v=G[ed].v; if (!cir[ed]){ Solve(u); Solve(v); R(v,1,3); J(u,v); C(u,1,3); R(u,3,2); return; } vector<int> path; path.pb(u); path.pb(v); int cur=v; while (1){ int p; for (p=head[cur];p;p=G[p].next) if (cir[p]==cir[ed] && !del[p]) break; del[p]=del[p^1]=1; if (V==u) break; path.pb(V); cur=V; } for (int x:path) Solve(x); R(v,1,3); J(u,v); C(u,1,3); int last=v; for (int i=2;i<(int)path.size();i++){ int x=path[i]; R(x,1,4); J(last,x); C(x,3,4); R(x,3,2); R(x,4,3); last=x; } C(u,1,3); R(u,3,2);}int main(){ int x,y,k; freopen("cactus.in","r",stdin); freopen("cactus.out","w",stdout); read(n); read(m); while (m--){ read(k); read(x); for (int i=2;i<=k;i++) read(y),Add(x,y),x=y; } dfs(1,0); for (int i=1;i<=n;i++) cur[i]=head[i]; Solve(1); printf("%d\n",(int)Ans.size()); for (info x:Ans) if (x.f=='j') printf("%c %d %d\n",x.f,x.x,x.y); else printf("%c %d %d %d\n",x.f,x.x,x.y,x.z); return 0;}
0 0
- [构造] Codeforces Gym 101190 NEERC 16 C. Cactus Construction
- [仙人掌同构 Hash] Codeforces Gym 100307 NEERC 13 C. Cactus Automorphisms
- [物理 杂题] Codeforces Gym 101190 NEERC 16 J. Jenga Boom
- [博弈论] Codeforces Gym 101190 NEERC 16 G. Game on Graph
- [杂题] Codeforces Gym 101190 NEERC 16 K. Kids Designing Kids
- [杂题] Codeforces Gym 101190 NEERC 16 L. List of Primes
- Codeforces Gym 101190 (NEERC 2016) A. Abbreviation
- [构造] Codeforces Gym 100553 NEERC 14 E. Epic Win!
- [树形DP 费用流手动增广] Codeforces Gym 101190 NEERC 16 M. Mole Tunnels
- [Trie树建图 2-SAT] Codeforces Gym 101190 NEERC 16 B. Binary Code
- [费用流建模] Codeforces Gym 101190 NEERC 16 D. Delight for a Cat
- [扫描线 杂题] Codeforces Gym 101190 NEERC 16 E. Expect to Wait
- [杂题 交互] Codeforces Gym 101190 NEERC 16 I. Indiana Jones and the Uniform Cave
- Codeforces Gym 101190 (NEERC 2016) F. Foreign Postcards (dp + 期望)
- Codeforces Gym 101190 (NEERC 2016) J. Jenga Boom
- Codeforces Gym 101190 NEERC 2016 B. Binary Code
- [可图性判定 Havel-Hakimi定理 构造] Codeforces Gym 100269 NEERC 13 Northern K. Kids in a Friendly Class
- Codeforces Gym 101190 (NEERC 2016) E. Expect to Wait (扫描线)
- 在U盘下安装ubuntu系统,从U盘启动Linux系统
- 支付宝接口对接
- python 数据分析入门(list set tuple dict)
- C++多态性的理解
- 初识QT5
- [构造] Codeforces Gym 101190 NEERC 16 C. Cactus Construction
- win32 API实现文件拖拽打开
- 使用angular ui-router的一点感受
- c++中的const
- P、NP、NPC和NP-Hard问题的通俗化解释和详细区分
- 虚拟存储器
- linux基础之系统虚拟机管理
- 求2^100Mod5
- 《穆斯林的葬礼》读后感