/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'void dfs(int)':
/in/foo.cc:50:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i = 0 ; i < linker[x].size() ; i++ )
                      ~~^~~~~~~~~~~~~~~~~~
/in/foo.cc:51:11: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
         if( cur != fa[x] )
           ^
/in/foo.cc: In function 'void dp(int)':
/in/foo.cc:68:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i = 0 ; i < linker[x].size() ; i++ )
                      ~~^~~~~~~~~~~~~~~~~~
# 状态 耗时 内存占用
#1 Accepted 118ms 65.75 MiB
#2 Accepted 43ms 62.219 MiB
#3 Accepted 44ms 65.363 MiB
#4 Accepted 44ms 64.855 MiB
#5 Accepted 53ms 65.465 MiB
#6 Accepted 44ms 62.348 MiB
#7 Accepted 1536ms 115.488 MiB
#8 Accepted 1444ms 114.363 MiB
#9 Accepted 1348ms 114.75 MiB
#10 Accepted 1298ms 113.969 MiB

代码

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <time.h>
#define MAXN 2000010
#define mod 19260817

using namespace std;

int n , m , x[ MAXN ] , y[ MAXN ] , fa[ MAXN ] , vis[ MAXN ] , belong[ MAXN ] , f[ MAXN ] , spe[ MAXN ] , cir , ans;
vector < int > linker[ MAXN ];

inline void update( int & x , int y )
{
    x += y;
    if( x >= mod ) x -= mod;
}

inline void addedge( int x , int y )
{
    linker[x].push_back( y ) , linker[y].push_back( x );
}

int read()
{
    int x=0;
    int f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
        f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
        
}


#define cur linker[x][i]

void dfs( int x )
{
    vis[x] = 1;
    for( int i = 0 ; i < linker[x].size() ; i++ )
        if( cur != fa[x] )
            if( !vis[ cur ] ) fa[ cur ] = x , dfs( cur );
            else if( !belong[ cur ] )
            {
                int v = x;
                spe[ ++cir ] = 1;
                while( 1 )
                {
                    belong[v] = cir;
                    if( v == cur ) break;
                    v = fa[v];
                }
            }
}

void dp( int x )
{
    for( int i = 0 ; i < linker[x].size() ; i++ )
        if( cur != fa[x] )
            fa[ cur ] = x , dp( cur ) , update( ans , f[x] * ( spe[x] ? 2ll : 1ll ) * f[ cur ] % mod ) , update( f[x] , f[ cur ] );
    if( spe[x] ) update( ans , f[x] ) , update( f[x] , f[x] + 1 );
}

int main()
{
    n = read() , m = read();
    for( register int i = 1 ; i <= m ; i++ ) addedge( x[i] = read() , y[i] = read() );
    dfs( 1 );
    for( register int i = 1 ; i <= n ; i++ )
    {
        linker[i].clear();
        if( !belong[i] )
            belong[i] = ++cir;
    }
    for( register int i = 1 ; i <= m ; i++ )
        if( belong[ x[i] ] != belong[ y[i] ] )
            addedge( belong[ x[i] ] , belong[ y[i] ] );
    memset( fa , 0 , sizeof( fa ) );
    dp( 1 );
    cout << ans << endl;
    return 0;
}

信息

递交者
类型
递交
题目
江边沼泽淹死村民(第一个ac奖励30元)
题目数据
下载
语言
C++
递交时间
2017-10-13 08:05:34
评测时间
2017-10-13 09:18:47
评测机
分数
100
总耗时
5977ms
峰值内存
115.488 MiB