답안 #593092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593092 2022-07-10T11:31:26 Z radal Subtree (INOI20_subtree) C++17
12 / 100
70 ms 17136 KB
#include <bits/stdc++.h>
//#pragma GCC target("sse,sse2")
//#pragma GCC optimize("unroll-loops,O3")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 1e5+5,mod = 1e9+7,inf = 1e9+10;
inline int mkay(int a,int b){
    if (a+b >= mod) return a+b-mod;
    if (a+b < 0) return a+b+mod;
    return a+b;
}
 
inline int poww(int a,int k){
    if (k < 0) return 0;
    int z = 1;
    while (k){
        if (k&1) z = 1ll*z*a%mod;
        a = 1ll*a*a%mod;
        k >>= 1;
    } 
    return z; 
}
int n,m,h[N],lw[N],dp[N][2][2][2]; // root bega
bool vis[N];
int mark[N];
vector<int> adj[N];
void pre(int v,int p){
    lw[v] = inf;
    vis[v] = 1;
    for (int u : adj[v]){
        if (u == p) continue;
        if (vis[u] && h[u] < h[v]){
            mark[v] = v;
            assert((lw[v] == inf));
            lw[v] = h[u];
            continue;
        }
        if (vis[u]) continue;
        h[u] = h[v]+1;
        pre(u,v);
        if (lw[u] <= h[v]){
            mark[v] = u;
            assert((lw[v] == inf));
            lw[v] = lw[u];
        }
    }
}
void dfs(int v){
    vis[v] = 1;
    for (int u : adj[v]) if (!vis[u])
        dfs(u);
    if (lw[v] > n){
        dp[v][1][0][0] = 1;
        dp[v][0][0][0] = 1;
        int t = 0;
        for (int u : adj[v]){
            if (h[u] == h[v]+1){
                t++;
                dp[v][0][0][0] = mkay(dp[v][0][0][0],mkay(dp[u][0][0][0],dp[u][0][0][1]));
                dp[v][1][0][0] = 1ll*dp[v][1][0][0]*mkay(dp[u][1][0][0],dp[u][1][0][1])%mod;
            }
        }
        dp[v][0][0][0] = mkay(dp[v][0][0][0],dp[v][1][0][0]);
        dp[v][1][0][0] = mkay(dp[v][1][0][0],1);
        dp[v][0][0][0] -= t;
        if (dp[v][0][0][0] < 0) dp[v][0][0][0] += mod;
        return;
    }
    if (mark[v] == v){
        int t = 0;
        dp[v][0][0][1] = 1;
        dp[v][1][1][0] = 1;
        dp[v][1][0][1] = 1;
        dp[v][1][1][1] = 1;
        for(int u : adj[v]){
            if (h[u] == h[v]+1){
                t++;
                dp[v][0][0][1] = mkay(dp[v][0][0][1],mkay(dp[u][0][0][0],dp[u][0][0][1]));
                dp[v][1][1][0] = 1ll*dp[v][1][1][0]*mkay(dp[u][1][0][0],dp[u][1][0][1])%mod;
            }
        }
        dp[v][0][1][0] = dp[v][1][1][0];
        dp[v][0][0][1] = mkay(dp[v][0][0][1],-t);
        dp[v][0][1][1] = dp[v][0][0][1];
        return;
    }
    if(lw[v] < h[v]){
        int t = 0;
        dp[v][1][0][1] = 1;
        dp[v][1][1][1] = 1;
        dp[v][1][0][0] = 1;
        dp[v][1][1][0] = 1;
        for (int u : adj[v]){
            if (h[u] == h[v]+1){
                t++;
                if (u == mark[v]){
                    dp[v][0][0][1] = mkay(dp[v][0][0][1],dp[u][0][1][1]);
                    dp[v][1][0][1] = 1ll*dp[v][1][0][1]*dp[u][1][0][1]%mod;
                    dp[v][0][1][1] = mkay(dp[v][0][1][1],dp[u][0][1][1]);
                    dp[v][1][1][1] = 1ll*dp[v][1][1][1]*dp[u][1][1][1]%mod;
                    dp[v][0][0][0] = mkay(dp[v][0][0][0],dp[u][0][1][0]);
                    dp[v][0][1][0] = mkay(dp[v][0][1][0],dp[u][0][1][0]);
                    dp[v][1][1][0] = 1ll*dp[v][1][1][0]*dp[u][1][1][0]%mod;
                    dp[v][1][0][0] = 1ll*dp[v][1][0][0]*dp[u][0][0][0]%mod;
                }
                else{
                    dp[v][0][0][1] = mkay(dp[v][0][0][1],mkay(dp[u][0][0][0],dp[u][0][0][1]));
                    dp[v][1][0][1] = 1ll*dp[v][1][0][1]*mkay(dp[u][1][0][1],dp[u][1][0][0])%mod;
                    dp[v][0][1][1] = mkay(dp[v][0][1][1],mkay(dp[u][0][0][1],dp[u][0][0][0]));
                    dp[v][1][1][1] = 1ll*dp[v][1][1][1]*mkay(dp[u][1][1][0],dp[u][1][1][1])%mod;
                    dp[v][1][1][0] = 1ll*dp[v][1][1][0]*mkay(dp[u][1][0][1],dp[u][1][0][0])%mod;
                    dp[v][1][0][0] = 1ll*dp[v][1][0][0]*mkay(dp[u][1][0][0],dp[u][1][0][1])%mod;
                }
            }
        }
        dp[v][0][0][1] = mkay(dp[v][0][0][1],-(t-1)+dp[v][1][0][1]);
        dp[v][0][1][1] = mkay(dp[v][0][1][1],-(t-1)+dp[v][1][1][1]);
        dp[v][0][0][0] = mkay(dp[v][0][0][0],dp[v][1][0][0]);
        dp[v][0][1][0] = mkay(dp[v][0][1][0],dp[v][1][1][0]);
        dp[v][1][1][1] = mkay(dp[v][1][1][1],1);
        dp[v][1][0][1] = mkay(1,dp[v][1][0][1]);
        return;
    }
    dp[v][1][0][0] = 1;
    dp[v][1][0][1] = 1;
    int t = 0;
    for (int u : adj[v]){
        if (h[u] == h[v]+1){
            t++;
            if (u == mark[v]){
                dp[v][1][0][0] = 1ll*dp[v][1][0][0]*dp[u][0][0][0]%mod;
                dp[v][1][0][1] = 1ll*dp[v][1][0][1]*dp[u][1][0][1]%mod;
                dp[v][0][0][1] = mkay(dp[v][0][0][1],mkay(dp[u][0][1][1],dp[u][0][1][0]));
            }
            else{
                dp[v][1][0][0] = 1ll*dp[v][1][0][0]*mkay(dp[u][1][0][1],dp[u][1][0][0])%mod;
                dp[v][1][0][1] = 1ll*dp[v][1][0][1]*mkay(dp[u][1][0][1],dp[u][1][0][0])%mod;
                dp[v][0][0][1] = mkay(dp[v][0][0][1],mkay(dp[u][0][0][1],dp[u][0][0][0]));
            }
        }
    }
    dp[v][1][0][1] = mkay(dp[v][1][0][1],1);
    dp[v][0][0][1] = mkay(dp[v][0][0][1],dp[v][1][0][1]-t);
    dp[v][0][0][0] = dp[v][1][0][0];
}
int main(){
    ios :: sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    rep(i,0,m){
        int u,v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    pre(1,0);
    memset(vis,0,sizeof vis);
    dfs(1);
    dp[1][0][0][0] = mkay(dp[1][0][0][0],dp[1][0][0][1]-1);
    cout << dp[1][0][0][0];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2772 KB Output is correct
2 Correct 1 ms 2772 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 1 ms 2772 KB Output is correct
5 Correct 1 ms 2772 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Incorrect 2 ms 2772 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 5 ms 3412 KB Output is correct
3 Correct 49 ms 9848 KB Output is correct
4 Correct 48 ms 9812 KB Output is correct
5 Correct 48 ms 9892 KB Output is correct
6 Correct 55 ms 9876 KB Output is correct
7 Correct 64 ms 15464 KB Output is correct
8 Correct 60 ms 13292 KB Output is correct
9 Correct 65 ms 13372 KB Output is correct
10 Correct 39 ms 10360 KB Output is correct
11 Correct 39 ms 9972 KB Output is correct
12 Correct 53 ms 9804 KB Output is correct
13 Correct 49 ms 9776 KB Output is correct
14 Correct 49 ms 12356 KB Output is correct
15 Correct 61 ms 16264 KB Output is correct
16 Correct 70 ms 17136 KB Output is correct
17 Correct 54 ms 9844 KB Output is correct
18 Correct 53 ms 9868 KB Output is correct
19 Correct 56 ms 9784 KB Output is correct
20 Correct 34 ms 10188 KB Output is correct
21 Correct 37 ms 10312 KB Output is correct
22 Correct 36 ms 10136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2772 KB Output is correct
2 Correct 1 ms 2772 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 1 ms 2772 KB Output is correct
5 Correct 1 ms 2772 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Incorrect 2 ms 2772 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2772 KB Output is correct
2 Correct 1 ms 2772 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 1 ms 2772 KB Output is correct
5 Correct 1 ms 2772 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Incorrect 2 ms 2772 KB Output isn't correct
8 Halted 0 ms 0 KB -