UVA 11324 The Largest Clique(强连通+dp)
来源:互联网 发布:领淘宝内部优惠券软件 编辑:程序博客网 时间:2024/06/10 04:37
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<stack>using namespace std;const int maxn=1000+5;struct edge{int u,v;}e[50000+5];vector<int> G[maxn];int pre[maxn],lowlink[maxn],sccno[maxn],dfs_clock,scc_cnt;int val[maxn],f[maxn];stack<int> s;int A[maxn][maxn];int n,m;void dfs(int u){ pre[u]=lowlink[u]=++dfs_clock; s.push(u); for(int i=0;i<G[u].size();i++){ int v=G[u][i]; if(!pre[v]){ dfs(v); lowlink[u]=min(lowlink[u],lowlink[v]); } else if(!sccno[v]){ lowlink[u]=min(lowlink[u],pre[v]); } } if(lowlink[u]==pre[u]){ scc_cnt++; int cnt=0; for(;;){ int x=s.top();s.pop(); cnt++; sccno[x]=scc_cnt; if(x==u) break; } val[scc_cnt]=cnt; }}void find_scc(){ dfs_clock=0;scc_cnt=0; memset(sccno,0,sizeof(sccno)); memset(pre,0,sizeof(pre)); for(int i=0;i<n;i++) if(!pre[i]) dfs(i);}int dp(int u){ int &ans=f[u]; if(ans>=0) return ans; ans=val[u]; for(int v=1;v<=scc_cnt;v++) if(A[u][v]) ans=max(ans,dp(v)+val[u]); return ans;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) G[i].clear(); for(int i=0;i<m;i++){ int u,v; scanf("%d%d",&u,&v); u--;v--; e[i].u=u;e[i].v=v; G[u].push_back(v); } find_scc(); memset(A,0,sizeof(A)); for(int i=0;i<m;i++){ int pu=sccno[e[i].u]; int pv=sccno[e[i].v]; if(pu!=pv) A[pu][pv]=1; } int ans=0; memset(f,-1,sizeof(f)); for(int i=1;i<=scc_cnt;i++) ans=max(ans,dp(i)); printf("%d\n",ans); } return 0;}
0 0
- uva 11324 The Largest Clique (强连通分量+dp)
- UVA 11324 - The Largest Clique(强连通分量+DP)
- UVA 11324 The Largest Clique(强连通+dp)
- UVa 11324 The Largest Clique (强连通分量,dp)
- uva11324 The Largest Clique --- 强连通+dp
- UVa 11324 The Largest Clique / 强连通分量
- UVA 11324 - The Largest Clique(强连通分量+缩点)
- UVA - 11324 The Largest Clique (DAG + 强连通分量)
- uva 11324 The Largest Clique(强连通分量 + DAG)
- UVA 11324 Problem B: The Largest Clique(强连通+DP,4级)
- UVA 11324 The Largest Clique (强连通分量+缩点+dp)
- UVA 11324 The Largest Clique(强连通分量+缩点DAG的DP)
- UVA 11324 The Largest Clique [强连通分量] [拓扑排序&dp]
- 【UVa】11324 The Largest Clique 强连通缩点+DP
- UVA 11324 The Largest Clique 强连通缩点+DP
- UVA 11324 The Largest Clique (强联通+DP)
- UVa11324 The Largest Clique(强连通分量+DP)
- uva 11324 The Largest Clique(强连通分量缩点+DAG动态规划)
- 本地host文件路径
- 考研路之极限
- 通过xml形式请求webService
- 【C语言】使用结构体数组
- Java性能、内存分析
- UVA 11324 The Largest Clique(强连通+dp)
- [js点滴]JavaScript进度事件09
- js实现html表格导出到excel
- 欢迎使用CSDN-markdown编辑器
- 几个C/Cpp笔试面试题目
- 【CJOJ P1365】最短路
- Caffe:Message type "caffe.LayerParameter" has no field named "reshape_param".
- Service生命周期
- java---《深入理解java虚拟机》第二章【java内存区域与内存溢出异常】阅读笔记