bzoj 1512 [POI2006]Pro-Professor Szu tarjan dp
来源:互联网 发布:rust辅助软件 编辑:程序博客网 时间:2024/06/07 15:21
先tarjan缩点,然后拓扑dp。
似乎有一些细节。。。
#include <bits/stdc++.h>using namespace std;#define N 1000010#define inf 36501int n,m,tot,top,cnt,scc,ans;int head[N],nex[N],to[N];int deep[N],low[N],st[N],bel[N];bool ins[N],vis[N];int du[N],size[N],f[N];vector<int>vec[N];void add(int x,int y){ tot++; nex[tot]=head[x];head[x]=tot; to[tot]=y;}void tarjan(int x){ deep[x]=low[x]=++cnt; st[++top]=x;ins[x]=1; for(int i=head[x];i;i=nex[i]) { if(!deep[to[i]]) tarjan(to[i]),low[x]=min(low[x],low[to[i]]); else if(ins[to[i]]) low[x]=min(low[x],deep[to[i]]); } if(deep[x]==low[x]) { int tmp=st[top--]; ins[tmp]=0;bel[tmp]=++scc; while(tmp!=x) { tmp=st[top--]; ins[tmp]=0;bel[tmp]=scc; } }}int main(){ //freopen("tt.in","r",stdin); scanf("%d%d",&n,&m);n++; for(int i=1,x,y;i<=m;i++) { scanf("%d%d",&x,&y); add(y,x); if(x==y)vis[x]=1; } for(int i=1;i<=n;i++) if(!deep[i])tarjan(i); for(int i=1;i<=n;i++)size[bel[i]]++; for(int i=1;i<=n;i++) for(int j=head[i];j;j=nex[j]) if(bel[i]!=bel[to[j]]) vec[bel[i]].push_back(bel[to[j]]),du[bel[to[j]]]++; for(int i=1;i<=n;i++) if(vis[i])size[bel[i]]++; int h=1,r=0; for(int i=1;i<=n;i++) if(!du[i])st[++r]=i; f[bel[n]]=1; if(size[bel[n]]>1)f[bel[n]]=inf; while(r>=h) { int tmp=st[h++]; for(int i=0,t;i<vec[tmp].size();i++) { f[t=vec[tmp][i]]+=f[tmp]; if(f[t]>inf||(size[t]>1&&f[t]))f[t]=inf; if(--du[t]==0)st[++r]=t; } } for(int i=1;i<n;i++) ans=max(ans,f[bel[i]]); if(ans!=inf)printf("%d\n",ans); else puts("zawsze"); for(int i=1;i<n;i++) if(f[bel[i]]==ans) st[++top]=i; printf("%d\n",top); for(int i=1;i<=top;i++) printf("%d ",st[i]); puts(""); return 0;}
0 0
- bzoj 1512 [POI2006]Pro-Professor Szu tarjan dp
- BZOJ 1512 [POI2006]Pro-Professor Szu Tarjan缩点+拓扑DP
- BZOJ 1512 [POI2006]Pro-Professor Szu Tarjan强连通分量 DP
- 【BZOJ】1512 [POI2006]Pro-Professor Szu 强联通分量+拓扑
- bzoj1512: [POI2006]Pro-Professor Szu
- BZOJ 1442: [Poi2006]Crystal dp
- BZOJ 1517 [POI2006]Met
- bzoj 1442: [Poi2006]Crystal
- BZOJ 1123 POI2008 BLO Tarjan+树形DP
- BZOJ 2427 软件安装 树形dp+tarjan
- BZOJ 1517 [POI2006]Met 贪心
- [bzoj]1520: [POI2006]Szk-Schools
- Professor John(DP)
- BZOJ 2427 HAOI 2010 软件安装 Tarjan+树上DP
- BZOJ 2427 [HNOI 2010] 软件安装 (tarjan+树形DP)
- bzoj 1123: [POI2008]BLO (tarjan求点双+树形DP)
- BZOJ 2427: [HAOI2010]软件安装 Tarjan缩点 + DP
- hdu 4649 Professor Tian (DP)
- Html5页面开发app之查询按钮悬浮窗
- android 实现文字滚动效果
- Java开发中常用的主流技术
- java Map使用遇到的问题
- CentOS7.2 源码安装Nginx 1.10.2
- bzoj 1512 [POI2006]Pro-Professor Szu tarjan dp
- 计算方法实验三 高斯消元
- 编译时“-nostdlib”的使用
- 1068. Find More Coins (30) (DFS + 回溯剪枝)
- HTTP 协议中的 Content-Encoding
- 如何在django使用多说评论系统
- 单内核与微内核
- MySQL的启动方式
- 聊天记录,踩的坑:设置EditText焦点;EditText软键盘和recyclerview的交互;SpannableStringBuilder的使用;ClickableSpan失效;软键盘挡住edi