zoukankan      html  css  js  c++  java
  • 【luogu P3388 割点(割顶)】 模板

    题目链接:https://www.luogu.org/problemnew/show/P3388

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define ll long long
    using namespace std;
    const int maxn = 500000 + 10;
    ll n, m, ans;
    ll dfn[maxn], low[maxn], tim;
    bool iscut[maxn];
    struct edge{
    	ll from, to, next;
    }e[maxn<<2];
    ll head[maxn], cnt;
    void add(ll u, ll v)
    {
    	e[++cnt].from = u;
    	e[cnt].next = head[u];
    	e[cnt].to = v;
    	head[u] = cnt;
    }
    void tarjan(ll x, ll fa)
    {
    	ll child = 0;
    	dfn[x] = low[x] = ++tim;
    	for(ll i = head[x]; i != -1; i = e[i].next)
    	{
    		ll v = e[i].to;
    		if(!dfn[v])
    		{
    			tarjan(v,fa);
    			low[x] = min(low[x], low[v]);
    			if(low[v] >= dfn[x] && x != fa) iscut[x] = 1;
    			if(x == fa) child++;
    		}
    		low[x] = min(low[x], dfn[v]);
    	}
    	if(x == fa && child >= 2) iscut[fa] = 1;
    }
    int main()
    {
    	freopen("testdata.in","r",stdin);
    	freopen("qwq.txt","w",stdout);
    	memset(head, -1, sizeof(head));
    	scanf("%lld%lld",&n,&m);
    	for(ll i = 1; i <= m; i++)
    	{
    		ll u, v;
    		scanf("%lld%lld",&u,&v);
    		add(u,v),add(v,u);
    	}
    	for(ll i = 1; i <= n; i++)
    		if(!dfn[i]) tarjan(i,i);
    	for(ll i = 1; i <= n; i++)
    		if(iscut[i] == 1) ans++;
    	printf("%lld
    ",ans);
    	for(ll i = 1; i <= n; i++)
    		if(iscut[i] == 1)printf("%lld ",i);
    	return 0;
    }
    
  • 相关阅读:
    解决ajax无法给js全局变量赋值的问题
    jquery对象和dom对象
    js浏览器调试
    elastic search使用
    elastic search远程测试
    elastic search安装与本地测试
    jQuery常用技巧
    Jquery操作cookie
    HTML特殊字符编码对照表
    DpQuery.js
  • 原文地址:https://www.cnblogs.com/MisakaAzusa/p/9372563.html
Copyright © 2011-2022 走看看