设为首页 加入收藏

TOP

最后的图不是强联通图(一)
2013-12-12 14:45:10 来源: 作者: 【 】 浏览:429
Tags:最后 不是 联通

    首先缩点,缩点之后就是一些强联通分量,其实我们很容易想到,要使最后的图不是强联通图,那么我们可以枚举每一个强联通的分量,设这个分量是最后与其他图不强联通的地方,那么除了这个分量,其他分量可以为完全图。 设总点数为n , 该分量点数为n' .
    那么我们可以计算出除了该点之外的其他分量变成完全图所需要的边数为,( n - n') * (n - n' - 1) - 已有的边数。
    所谓已有的边数就是其他强联通里面已经存在的边,我们要减掉。具体看代码实现吧。
    然后还有一部分就是其实我们枚举出来的这个强联通分量,他也是可以成为一个完全图的,那么增加的边数为(n' * (n' -1)) - 已有的边数。
    最后还有一部分就是完全图到枚举的强联通分量之间的边,这部分的边就是n * n' - (n到n'之间的桥数) .
    最后更新答案取最大值就可以了。
    我SB的把枚举那个条件判断成out[i] == 0,死都出不来,最后加上in[i] == 0就A掉了。
    我是SB吗?
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <string>
    #include <cmath>
    #include <cstring>
    #include <queue>
    #include <set>
    #include <vector>
    #include <stack>
    #include <map>
    #include <iomanip>
    #define PI acos(-1.0)
    #define Max 2505
    #define inf 1《28
    #define LL(x) ( x 《 1 )
    #define RR(x) ( x 《 1 | 1 )
    #define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i )
    #define ll __int64
    #define mem(a,b) memset(a,b,sizeof(a))
    #define mp(a,b) make_pair(a,b)
    #define PII pair<int,int>
    using namespace std;
    inline void RD(int &ret) {
    char c;
    do {
    c = getchar();
    } while(c < '0' || c > '9') ;
    ret = c - '0';
    while((c=getchar()) >= '0' && c <= '9')
    ret = ret * 10 + ( c - '0' );
    }
    inline void OT(int a) {
    if(a >= 10)OT(a / 10) ;
    putchar(a % 10 + '0') ;
    }
    #define M 1000005
    #define N 100005
    int n , m ;
    struct kdq {
    int e , next ;
    } ed[M] ,ed1[M] ;
    struct B{
    int s, e ;
    }br[N] ;
    int head[N] , num ;
    int head1[N] ,num1 ;
    void add(int s , int e) {
    ed[num].e = e ;
    ed[num].next = head[s] ;
    head[s] = num ++ ;
    }
    void add1(int s ,int e){
    ed1[num1].e = e ;
    ed1[num1].next = head1[s] ;
    head1[s] = num1 ++ ;
    }
    bool vis[N] ;
    int BB[N] ;
    int dfn[N] ,low[N] , st[N] ,belong[N] ,cnt[N] ,out[N] , in[N] ,edg[N] , edn ;
    int ca , tp , dp ;
    void init() {
    num1 = edn = num = ca = tp = dp = 0 ;
    mem(dfn ,-1) ;
    mem(low ,0) ;
    mem(head, -1) ;
    mem(st, 0) ;
    mem(vis ,0) ;
    mem(belong ,0) ;
    mem(in , 0) ;
    mem(out, 0) ;
    mem(edg, 0) ;
    mem(head1, -1) ;
    mem(cnt ,0) ;
    mem(BB ,0) ;
    }

   

首页 上一页 1 2 3 4 5 下一页 尾页 1/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++后缀数组练习题 下一篇区间动态规划定义区间DP

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·PostgreSQL 索引 - (2025-12-25 22:20:43)
·MySQL Node.js 连接 (2025-12-25 22:20:41)
·SQL 撤销索引、表以 (2025-12-25 22:20:38)
·Linux系统简介 (2025-12-25 21:55:25)
·Linux安装MySQL过程 (2025-12-25 21:55:22)