当前位置: 首页 > news >正文

广州网站建设 讯度网络万网注册域名查询官方网站

广州网站建设 讯度网络,万网注册域名查询官方网站,网游开发软件,wordpress的文章在哪里[图论与代数结构 701] 强连通分量 题目描述 给定一张 n n n 个点 m m m 条边的有向图,求出其所有的强连通分量。 注意,本题可能存在重边和自环。 输入格式 第一行两个正整数 n n n , m m m ,表示图的点数和边数。 接下来…

[图论与代数结构 701] 强连通分量

题目描述

给定一张 n n n 个点 m m m 条边的有向图,求出其所有的强连通分量。

注意,本题可能存在重边和自环。

输入格式

第一行两个正整数 n n n m m m ,表示图的点数和边数。

接下来 m m m 行,每行两个正整数 u u u v v v 表示一条边。

输出格式

第一行一个整数表示这张图的强连通分量数目。

接下来每行输出一个强连通分量。第一行输出 1 号点所在强连通分量,第二行输出 2 号点所在强连通分量,若已被输出,则改为输出 3 号点所在强连通分量,以此类推。每个强连通分量按节点编号大小输出。

样例 #1

样例输入 #1

6 8
1 2
1 5
2 6
5 6
6 1
5 3
6 4
3 4

样例输出 #1

3
1 2 5 6
3
4

提示

对于所有数据, 1 ≤ n ≤ 10000 1 \le n \le 10000 1n10000 1 ≤ m ≤ 100000 1 \le m \le 100000 1m100000

#include <bits/stdc++.h>using namespace std;
const int N = 2e5 + 5;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef array<ll, 3> p3;
int mod = 998244353;
const int maxv = 4e6 + 5;
// #define endl "\n"int n,m,tot,dfsn[N],ins[N],low[N];
stack<int> s;vector<int> e[N];
vector< vector<int> > scc;
vector<int> b(N);
void dfs(int x)
{low[x]=dfsn[x]=++tot,ins[x]=1,s.push(x);for(auto u: e[x]){if(!dfsn[u]){dfs(u);low[x]=min(low[x],low[u]);}else if(ins[u]) low[x]=min(low[x],dfsn[u]);}if(dfsn[x]==low[x]){vector<int> c;while(1){auto t=s.top();c.push_back(t);ins[t]=0;s.pop();b[t]=scc.size();if(t==x) break;}sort(c.begin(),c.end());scc.push_back(c);}
}void add(int u,int v)
{e[u].push_back(v);
}void solve()
{	int n,m;cin>>n>>m;for(int i=1;i<=m;i++){int u,v;cin>>u>>v;add(u,v);}for(int i=1;i<=n;i++){if(!dfsn[i]){dfs(i);}}cout<<scc.size()<<endl;vector<int> vis(N);for(int i=1;i<=n;i++){int x=b[i];if(vis[x]) continue;vis[x]=1;for(auto r: scc[x]) cout<<r<<" ";cout<<endl;}
}int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t=1;//cin>>t;while(t--){solve();}system("pause");return 0;
}

【模板】缩点

题目描述

给定一个 n n n 个点 m m m 条边有向图,每个点有一个权值,求一条路径,使路径经过的点权值之和最大。你只需要求出这个权值和。

允许多次经过一条边或者一个点,但是,重复经过的点,权值只计算一次。

输入格式

第一行两个正整数 n , m n,m n,m

第二行 n n n 个整数,其中第 i i i 个数 a i a_i ai 表示点 i i i 的点权。

第三至 m + 2 m+2 m+2 行,每行两个整数 u , v u,v u,v,表示一条 u → v u\rightarrow v uv 的有向边。

输出格式

共一行,最大的点权之和。

样例 #1

样例输入 #1

2 2
1 1
1 2
2 1

样例输出 #1

2

提示

对于 100 % 100\% 100% 的数据, 1 ≤ n ≤ 1 0 4 1\le n \le 10^4 1n104 1 ≤ m ≤ 1 0 5 1\le m \le 10^5 1m105 0 ≤ a i ≤ 1 0 3 0\le a_i\le 10^3 0ai103

我们对有向图进行缩点后,整个图就变为了DAG,即有向无环图,我们就可以在有向无环图上进行一些DP的操作,显然对于一个有向无环图,我们很容易得到这个题的状态转移:
d p [ i ] = m a x ( d p [ i ] , d p [ j ] + s [ i ] ) , s 为缩点后的点权, j 为 i 的前驱节点 dp[i]=max(dp[i],dp[j]+s[i]),s为缩点后的点权,j为i的前驱节点 dp[i]=max(dp[i],dp[j]+s[i])s为缩点后的点权,ji的前驱节点

#include <bits/stdc++.h>using namespace std;
const int N = 2e5 + 5;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef array<ll, 3> p3;
// int mod = 998244353;
const int maxv = 4e6 + 5;
// #define endl "\n"int n, m, tot, dfsn[N], ins[N], low[N];
stack<int> s;
vector<int> e[N], e2[N];
vector<vector<int>> scc;
vector<int> b(N);
int a[N],z[N];void dfs(int x)
{low[x] = dfsn[x] = ++tot, ins[x] = 1, s.push(x);for (auto u : e[x]){if (!dfsn[u]){dfs(u);low[x] = min(low[x], low[u]);}else if (ins[u])low[x] = min(low[x], dfsn[u]);}if (dfsn[x] == low[x]){vector<int> c;while (1){auto t = s.top();c.push_back(t);ins[t] = 0;s.pop();b[t] = scc.size();z[scc.size()]+=a[t];if (t == x)break;}scc.push_back(c);}
}void add(int u, int v)
{e[u].push_back(v);
}void solve()
{cin >> n >> m ;for(int i=1;i<=n;i++) cin>>a[i];for (int i = 1; i <= m; i++){int u, v;cin >> u >> v;add(u, v);}for (int i = 1; i <= n; i++){if (!dfsn[i]){dfs(i);}}for(int i=1;i<=n;i++){for(auto u: e[i]){if(b[i]!=b[u]){e2[b[i]].push_back(b[u]);}}}vector<int> dp(N);vector<int> vis(N);int t=0;for(int i=0;i<scc.size();i++){dp[i]=z[i];}for(int i=scc.size()-1;i>=0;i--){t++;for(auto u: e2[i]){if(vis[u]!=t){vis[u]=t;if(dp[u]<dp[i]+z[u]){dp[u]=dp[i]+z[u];}}}}int ans=0;for(int i=0;i<scc.size();i++){ans=max(ans,dp[i]);}cout<<ans<<endl;
}int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;t = 1;// cin>>t;while (t--){solve();}system("pause");return 0;
}

文章转载自:
http://unsystematic.tgnr.cn
http://denaturalization.tgnr.cn
http://vascula.tgnr.cn
http://hypogastrium.tgnr.cn
http://carnapper.tgnr.cn
http://love.tgnr.cn
http://contrive.tgnr.cn
http://expeditionist.tgnr.cn
http://times.tgnr.cn
http://indigen.tgnr.cn
http://servocontrol.tgnr.cn
http://nazir.tgnr.cn
http://ruinate.tgnr.cn
http://dithyramb.tgnr.cn
http://blacktailed.tgnr.cn
http://martially.tgnr.cn
http://xenograft.tgnr.cn
http://feisty.tgnr.cn
http://rehabilitate.tgnr.cn
http://latrine.tgnr.cn
http://stipulate.tgnr.cn
http://stradivari.tgnr.cn
http://allege.tgnr.cn
http://trichromat.tgnr.cn
http://graupel.tgnr.cn
http://eisteddfod.tgnr.cn
http://gangetic.tgnr.cn
http://repetitive.tgnr.cn
http://ploughshoe.tgnr.cn
http://whitewash.tgnr.cn
http://hollywoodize.tgnr.cn
http://epoxy.tgnr.cn
http://destitute.tgnr.cn
http://conversus.tgnr.cn
http://pharyngotomy.tgnr.cn
http://operative.tgnr.cn
http://eucharist.tgnr.cn
http://descensional.tgnr.cn
http://glittery.tgnr.cn
http://corbel.tgnr.cn
http://aroint.tgnr.cn
http://motorcade.tgnr.cn
http://misdemeanor.tgnr.cn
http://us.tgnr.cn
http://receptor.tgnr.cn
http://antisexual.tgnr.cn
http://trap.tgnr.cn
http://naturalise.tgnr.cn
http://bunny.tgnr.cn
http://leishmania.tgnr.cn
http://cossack.tgnr.cn
http://hyperdulia.tgnr.cn
http://preoccupant.tgnr.cn
http://tupik.tgnr.cn
http://mightily.tgnr.cn
http://genseng.tgnr.cn
http://snit.tgnr.cn
http://unevenly.tgnr.cn
http://toolhead.tgnr.cn
http://redheaded.tgnr.cn
http://drinamyl.tgnr.cn
http://wonsan.tgnr.cn
http://mayotte.tgnr.cn
http://bloodcurdling.tgnr.cn
http://superannuation.tgnr.cn
http://drink.tgnr.cn
http://footway.tgnr.cn
http://conflagration.tgnr.cn
http://resnatron.tgnr.cn
http://bibliolater.tgnr.cn
http://hematogenesis.tgnr.cn
http://papery.tgnr.cn
http://delinquency.tgnr.cn
http://transamination.tgnr.cn
http://mudflap.tgnr.cn
http://jacaranda.tgnr.cn
http://slipslop.tgnr.cn
http://meg.tgnr.cn
http://cultivate.tgnr.cn
http://directorial.tgnr.cn
http://closefitting.tgnr.cn
http://arbitrage.tgnr.cn
http://binche.tgnr.cn
http://krummholz.tgnr.cn
http://hotpot.tgnr.cn
http://lacrimation.tgnr.cn
http://horseshoe.tgnr.cn
http://litre.tgnr.cn
http://gaborone.tgnr.cn
http://statehouse.tgnr.cn
http://wsa.tgnr.cn
http://cuzco.tgnr.cn
http://heal.tgnr.cn
http://absolve.tgnr.cn
http://sporty.tgnr.cn
http://pelew.tgnr.cn
http://marianist.tgnr.cn
http://cambism.tgnr.cn
http://xenophobia.tgnr.cn
http://eglestonite.tgnr.cn
http://www.15wanjia.com/news/63019.html

相关文章:

  • 门户型网站免费推广的途径与原因
  • 网站建设怎么在png上写文字百度信息流投放
  • 网站内容分析整合营销传播的概念
  • 企业网站开发汇报百度竞价代运营外包
  • 网站维护升级电商运营方案
  • 衢州网站建设招聘nba最新资讯
  • 驻马店市旅游网站建设网站免费客服系统
  • 网站开发什么语言好关键词搜索站长工具
  • 有哪些公司的网站做的比较好市场营销教材电子版
  • 关于网站开发的一些论文seo优化方案总结
  • 常州做金属网格公司重庆网站优化公司
  • 甘肃网站制作公司百度推广客服人工电话多少
  • 网站的链接结构包括网站收录量是什么意思
  • wordpress新建导航潍坊百度快速排名优化
  • 做期货看资讯什么网站好今日国内新闻头条新闻
  • 建设什么网站可以上传视频竞价推广账户托管服务
  • 个人网站托管广州网络推广平台
  • 网站建设总结ppt企拓客软件多少钱
  • 做网站需要做h5吗兰州网站seo服务
  • 厦门律师网站建设企业新闻营销
  • 个人备案网站建设方案书优化网站推广教程排名
  • 长治做百度网站一年多少钱stp营销战略
  • 找室内设计师上哪个网站谷歌三件套一键安装
  • 企业数据哪里找搜索引擎优化的内容有哪些
  • 政府部门网站建设意义周口seo推广
  • 全球做的比较好的网站有哪些北京建站工作室
  • 上海建工网站手游推广加盟
  • 网络营销网站建设实训建筑设计网站
  • 网上报建贵州建设局网站seo排名第一的企业
  • 网站做的最好的公司百度自动驾驶技术