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
  • 相关阅读:
    DAO模式多表联查
    使用ADO.NET访问数据库
    连接查询和分组查询
    模糊查询和聚合函数
    poj 1220 NUMBER BASE CONVERSION
    poj 1964 City Game
    Odd number problem
    POJ 2983 M × N Puzzle
    L O V E
    【Mybatis】【3】处理大于号小于号及其他特殊字符
  • 原文地址:https://www.cnblogs.com/acm1ruoji/p/10668034.html
Copyright © 2011-2022 走看看