首页 > 其他分享 >Tarjan模板

Tarjan模板

时间:2024-05-09 10:00:56浏览次数:18  
标签:Tarjan int sccno num low include 模板

Tarjan模板

#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<cmath>
#include<limits.h>
#include<climits>
#include<fstream>
#include<set>
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
int cnt;//强连通分量的个数
int low[N], num[N], dfn;
int sccno[N], top;//sccno::SCC Number,就是第几个SCC的编号
int stack[N];
vector<int>G[N];
void dfs(int u)//u:父节点,v:子节点
{
	stack[top++] = u;
	low[u] = num[u] = ++dfn;//num[u]同时担负了判断是否进入的职责
	for (int i = 0; i < G[u].size(); ++i)
	{
		int v = G[u][i];
		if (!num[v])
		{
			dfs(v);
			low[u] = min(low[v], low[u]);

		}
		else if (!sccno[v])//如果没有scc编号,但是又跳到跳过的位置
			low[u] = min(low[u], num[v]);
	}
	if (low[u] == num[u])
	{
		cnt++;
		while (1)//该点以上都是一个scc
		{
			int v = stack[--top];
			sccno[v] = cnt;
			if (u == v)break;
		}
	}
}
void Tarjan(int n)
{
	cnt = top = dfn = 0;
	memset(sccno, 0, sizeof(sccno));
	memset(num, 0, sizeof(num));
	memset(low, 0, sizeof(low));
	for (int i = 1; i <= n; i++)
		if (!num[i])
			dfs(i);//防止不连通
}
int main()
{
	int n, m, u, v;
	cin >> n >> m;//n:点,m:边
	for (int i = 0; i < m; i++)
	{
		cin >> u >> v;
		G[u].push_back(v);
	}
	Tarjan(n);
	return 0;
}

标签:Tarjan,int,sccno,num,low,include,模板
From: https://www.cnblogs.com/zzzsacmblog/p/18181474

相关文章

  • string:Python的文本常量与字符串模板
    前言在程序中,有很多高效率的字符串处理方式,如果开发者能够完全掌握这些高效的字符串处理,往往在开发者也能事半功倍。比如针对于字符串的处理,也是自然语言处理的基础知识。而python3中,处理字符串的库为:string。本篇将详细介绍各种字符串的高效处理方式。首字母大写对于英文单词......
  • 快读模板
    快读模板getchar()inlineintread(){ints=0,w=1;//s数值w符号charch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w*=-1;ch=getchar();}while('0'<......
  • c++ 模板模板参数("Template Template Parameters")
    #include<iostream>#include<vector>#include<list>usingnamespacestd;namespace_nmsp1{//T类型模板参数,代表容器中元素类型//Container代表的不是一个类型(不能是一个类型模板参数),而是一个类模板(类名)//Container不叫做类型模板参数,而叫做模板模......
  • P3383 【模板】线性筛素数
    原题链接题解关键因素:任何合数都可以分为最小质数乘上另外一个数code#include<bits/stdc++.h>usingnamespacestd;vector<int>ans;intmain(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);intn;cin>>n;vector<int>vis(n+5,0);......
  • AlmaLinux 9.3 x86_64 OVF (sysin) - VMware 虚拟机模板
    AlmaLinux9.3x86_64OVF(sysin)-VMware虚拟机模板由社区提供的免费Linux操作系统,RHEL二进制兼容发行版。请访问原文链接:AlmaLinux9x86_64OVF(sysin)-VMware虚拟机模板,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgAlmaLinuxrelease9.3(Shamroc......
  • 代理 mitmproxy config.yaml 模板 使用笔记(二)
    代理mitmproxyconfig.yaml模板使用笔记(二)mitmproxyconfig.yaml模板使用mitmproxy可能需要用到config.yaml来批量配置参数目录config.yaml文件所在位置config.yaml配置模板文件位置配置文件默认读取路径:~/.mitmproxy/config.yaml,见配置项:confdir:'~/.mitmpro......
  • 【GD32】---- 移植工程模板
    1新建模板文件夹新建一个名叫03_GD32TemplateProject的文件夹,用于建造工程模板2移植官方库文件在模板文件夹里新建5个文件夹,分别存放官方库文件和系统驱动文件01_main存放main函数02_Startup存放系统启动文件03_System存放官方的系统文件04_Firmware_PeripheralD......
  • 【 攻防实操系列+漏洞复现 】-- Jinja2 SSTI模板注入
    框架:python---Flask描述:Flask是一个使用Python编写的轻量级Web应用框架。其WSGI工具箱采用Werkzeug,模板引擎则使用Jinja2漏洞复现:Jinja2SSTI模板注入使用vulhub靶场,启动环境先进入容器看一下web服务的代码,得出参数值为name,且可控判断是否存在ssti漏洞,输入:?name={{1*9}},......
  • luogu P6329 【模板】点分树 | 震波
    //【模板】点分树|震波//https://www.luogu.com.cn/problem/P6329#include<bits/stdc++.h>#definedebug(a)cerr<<"Line:"<<__LINE__<<""#a<<endl#defineprint(a)cerr<<#a"="<<(a)<<endl#d......
  • git使用模板编辑commit message
    创建commitmessage模板1.创建一个名为commit.template的模板文件:[problemdescription]:[rootcause]:[change]:[changetype]:[sideeffects]:[reviewer]:[selftest]:[testcase]:2.在git中设置模板路径:只在当前git管理的代码中使用此模板,在当前......