SDUT 2170 The Largest SCC
来源:互联网 发布:notepad++ mac版中文 编辑:程序博客网 时间:2024/06/06 02:59
一句话题意:
给出一个点数
首先做一次强连通分量的缩点肯定是不吃亏的(笑
如果第
如果第
具体的代码实现的,我们可以先预处理一个
我是代码的分割线
#include<bits/stdc++.h>using namespace std;const int maxn = 1123;int dfn[maxn],low[maxn],_cnt;int bel[maxn];vector<int>edge[maxn];vector<int>scc[maxn];stack<int> S;void init(int n){ for(int i=0;i<n;i++){ edge[i].clear(); } while(S.empty()==false) S.pop(); memset(dfn,-1,sizeof(dfn)); memset(low,-1,sizeof(low)); memset(bel,-1,sizeof(bel)); _cnt = 1;}void dfs(int st){ S.push(st); dfn[st] = low[st] = _cnt++; for(vector<int>::iterator it = edge[st].begin();it!=edge[st].end();it++){ int x = *it; if(dfn[x] == -1){ dfs(x); low[st] = min(low[st],low[x]); } else if(bel[x] == -1){ low[st] = min(low[st],dfn[x]); } } if(low[st] == dfn[st]){ while(S.top()!=st){ bel[S.top()] = st; S.pop(); } bel[st] = st; S.pop(); }}const int maxm = 21234;int from[maxm],to[maxm];int cnt[maxn];bool viser[maxn][maxn];void dffs(int st,bool *s){ s[st] = true; for(vector<int>::iterator it = scc[st].begin();it!=scc[st].end();it++){ if(s[*it] == false){ dffs(*it,s); } }}void getvis(int n){ for(int i=1;i<=n;i++){ scc[i].clear(); } for(int st = 1;st <= n;st++){ for(vector<int>::iterator it = edge[st].begin();it!=edge[st].end();it++){ int f = bel[st]; int t = bel[*it]; if(f != t){ scc[f].push_back(t); } } } memset(viser,0,sizeof(viser)); for(int i=1;i<=n;i++){ if(bel[i] == i){ dffs(i,viser[i]); } }}int main(){ int T; scanf("%d",&T); int n ,m; int q; while(T-- && ~scanf("%d %d %d",&n,&m,&q)){ init(n); for(int i=1;i<=m;i++){ scanf("%d %d",&from[i],&to[i]); edge[from[i]].push_back(to[i]); } for(int i=1;i<=n;i++){ if(bel[i] == -1){ dfs(i); } } memset(cnt,0,sizeof(cnt)); for(int i=1;i<=n;i++){ cnt[bel[i]]++; } getvis(n); int x; int maxer = *max_element(cnt+1,cnt+1+n); while(q--){ scanf("%d",&x); int f = bel[from[x]],t = bel[to[x]]; if(f == t){ printf("%d\n",maxer); } else{ int ans = 0; for(int i=1;i<=n;i++){ if(viser[f][i] && viser[i][t]){ ans += cnt[i]; } } printf("%d\n",max(maxer,ans)); } } } return 0;}
0 0
- SDUT 2170 The Largest SCC
- sdut 2170 The Largest SCC
- sdut 2170 The Largest SCC(山东第二届省赛)
- SDUT-2170-The Largest SCC(强连通分量)
- SDUT 2170 The Largest SCC(强连通+边的变换)
- UVa11324 - The Largest Clique(DAG+DP+SCC)
- UVA11324-- The Largest Clique(SCC+DP)
- UVAlive11324 The Largest Clique(scc+dp)
- UVA 11324 The Largest Clique(SCC+DP)
- UVA11324.The Largest Clique最大团——scc+dp
- [UVA 11324]The Largest Clique[SCC][缩点]
- UVA 11324 The Largest Clique(SCC+dp)
- UVA 11324 - The Largest Clique(SCC缩点 + DP)
- 【Uva11324】The Largest Clique【SCC】【最长路】【有向图最大团】
- sdut 3262 Circle of Friends (SCC缩点)
- SCC
- UVA11324 The Largest Clique
- The Largest Clique
- Redis 起步
- ios 支付宝:移动支付1
- 图像去雾
- 125. Valid Palindrome [easy] (Python)
- MAC常用命令和常用软件列表
- SDUT 2170 The Largest SCC
- IOS 审核 被拒 及 解决
- Nginx打开目录浏览功能(autoindex)
- 如何用Maven创建web项目(具体步骤)
- js 浏览器写coke
- ViBe前景检测算法
- bzoj 1912: [Apio2010]patrol 巡逻
- 关于rest的一些标注
- 五、SpringBoot JPA 配置redis