zoukankan      html  css  js  c++  java
  • 华华和月月逛公园(牛客小白赛)

    https://ac.nowcoder.com/acm/contest/392/I

    #include <bits/stdc++.h>
    using namespace std;
    #define re register
    #define ll long long
    const int maxn=1e5+10;
    void read(int &a)
    {
        a=0;
        int d=1;
        char ch;
        while(ch=getchar(),ch>'9'||ch<'0')
            if(ch=='-')
                d=-1;
        a=ch-'0';
        while(ch=getchar(),ch>='0'&&ch<='9')
            a=a*10+ch-'0';
        a*=d;
    }
    void write(int x)
    {
        if(x<0)
            putchar(45),x=-x;
        if(x>9)
            write(x/10);
        putchar(x%10+'0');
    }
    int head[maxn],low[maxn],dfn[maxn],num,cnt,ans;
    struct note
    {
        int v,next;
    }q[6*maxn];
    void add(int u,int v)
    {
        q[++num].next=head[u];
        q[num].v=v;
        head[u]=num;
    }
    void tarjan(int x,int fa)
    {
        low[x]=dfn[x]=++cnt;
        for(re int i=head[x];i;i=q[i].next)
        {
            int v=q[i].v;
            if(v==fa)
                continue;
            if(!dfn[v])
            {
                tarjan(v,x);
                low[x]=min(low[v],low[x]);
                if(low[v]>dfn[x])
                    ans++;
            }
            else low[x]=min(low[x],dfn[v]);
        }
    }
    int main()
    {
        int n,m;
        read(n);
        read(m);
        for(re int i=0;i<m;i++)
        {
            int a,b;
            read(a);
            read(b);
            add(a,b);
            add(b,a);
        }
        for(re int i=1;i<=n;i++)
        {
            if(!dfn[i])
                tarjan(i,0);
        }
        write(m-ans);
        return 0;
    }
    View Code
  • 相关阅读:
    jquery 里面对数组去重操作-unique
    jquery序列化form表单
    [转载]说说JSON和JSONP,也许你会豁然开朗,含jQuery用例
    AMD和CMD的区别
    CSS中!important的使用
    HTML的map-area的使用
    CSS Sprite 精灵图
    UA 用户代理
    IE haslayout
    心情随笔
  • 原文地址:https://www.cnblogs.com/acm1ruoji/p/10668034.html
Copyright © 2011-2022 走看看