답안 #469048

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469048 2021-08-30T14:03:16 Z alirezasamimi100 Subtree (INOI20_subtree) C++17
50 / 100
146 ms 29256 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")*/
/*#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")*/
using namespace std;
using ll=long long int;
using ld=long double;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define lc v<<1
#define rc v<<1|1
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int N=2e5+10,LN=18,M=5e5+10,SQ=350,B=737,inf=1e9+10;
const ll INF=1e18;
const ld ep=1e-7;
const int MH=1000696969,MD=998244353,MOD=1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
    ll ans=1;
    while (y != 0) {
        if (y & 1) ans = ans * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return ans;
}
ll n,m,ans,fl[N],P[N],dp[N],pd[N],dd[N];
vector<ll> adj[N],c[N];
void dfs(ll v, ll p){
    fl[v]=v;
    P[v]=p;
    for(ll u : adj[v]){
        if(u==p || fl[u]==fl[v]) continue;
        if(!fl[u]) dfs(u,v);
        else{
            ll x=v;
            while(x!=u){
                fl[x]=u;
                c[u].pb(x);
                x=P[x];
            }
        }
    }
}
void sfd(ll v, ll p){
    for(ll t : c[v]){
        pd[t]=1;
        for(ll u : adj[t]){
            u=fl[u];
            if(u!=p && u!=v){
                sfd(u,v);
                pd[t]=pd[t]*(dp[u]+1)%MOD;
            }
        }
    }
    if(c[v].size()==1){
        dp[v]=pd[v];
        ans=(ans+dp[v])%MOD;
        return;
    }
    dd[c[v].size()]=1;
    dd[c[v].size()+1]=0;
    ll t=0;
    for(ll i=c[v].size()-1; i; i--){
        dd[i]=dd[i+1]*pd[c[v][i]]%MOD;
        t=(t+1)*pd[c[v][i]]%MOD;
        ans=(ans+t)%MOD;
    }
    for(ll i=c[v].size()-1; i; i--){
        dd[i]+=dd[i+1];
    }
    t=1;
    for(ll i=0; i<c[v].size(); i++){
        t=t*pd[c[v][i]]%MOD;
        dp[v]=(dp[v]+t*dd[i+2])%MOD;
    }
    ans=(ans+dp[v])%MOD;
}
int main(){
    fast_io;
    cin >> n >> m;
    for(ll i=0; i<m; i++){
        ll v,u;
        cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
    }
    dfs(1,0);
    for(ll i=1; i<=n; i++){
        if(fl[i]==i){
            c[i].pb(i);
            reverse(c[i].begin(),c[i].end());
        }
    }
    sfd(1,0);
    cout << ans << '\n';
    return 0;
}

Compilation message

Main.cpp: In function 'void sfd(ll, ll)':
Main.cpp:84:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for(ll i=0; i<c[v].size(); i++){
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 6 ms 9676 KB Output is correct
3 Correct 6 ms 9676 KB Output is correct
4 Correct 7 ms 9676 KB Output is correct
5 Correct 6 ms 9676 KB Output is correct
6 Correct 6 ms 9752 KB Output is correct
7 Correct 7 ms 9676 KB Output is correct
8 Correct 6 ms 9676 KB Output is correct
9 Correct 7 ms 9676 KB Output is correct
10 Correct 7 ms 9676 KB Output is correct
11 Correct 6 ms 9676 KB Output is correct
12 Correct 6 ms 9676 KB Output is correct
13 Correct 6 ms 9676 KB Output is correct
14 Correct 5 ms 9676 KB Output is correct
15 Correct 6 ms 9752 KB Output is correct
16 Correct 6 ms 9744 KB Output is correct
17 Correct 6 ms 9676 KB Output is correct
18 Correct 6 ms 9676 KB Output is correct
19 Correct 6 ms 9676 KB Output is correct
20 Correct 5 ms 9676 KB Output is correct
21 Correct 5 ms 9676 KB Output is correct
22 Correct 6 ms 9676 KB Output is correct
23 Correct 6 ms 9676 KB Output is correct
24 Correct 6 ms 9708 KB Output is correct
25 Correct 6 ms 9676 KB Output is correct
26 Correct 7 ms 9676 KB Output is correct
27 Correct 6 ms 9676 KB Output is correct
28 Correct 6 ms 9676 KB Output is correct
29 Correct 6 ms 9676 KB Output is correct
30 Correct 6 ms 9664 KB Output is correct
31 Correct 6 ms 9676 KB Output is correct
32 Correct 6 ms 9676 KB Output is correct
33 Correct 6 ms 9676 KB Output is correct
34 Correct 6 ms 9680 KB Output is correct
35 Correct 6 ms 9676 KB Output is correct
36 Correct 6 ms 9676 KB Output is correct
37 Correct 6 ms 9676 KB Output is correct
38 Correct 8 ms 9676 KB Output is correct
39 Correct 6 ms 9676 KB Output is correct
40 Correct 6 ms 9664 KB Output is correct
41 Correct 6 ms 9676 KB Output is correct
42 Correct 6 ms 9692 KB Output is correct
43 Correct 6 ms 9676 KB Output is correct
44 Correct 6 ms 9676 KB Output is correct
45 Correct 6 ms 9684 KB Output is correct
46 Correct 6 ms 9676 KB Output is correct
47 Correct 6 ms 9676 KB Output is correct
48 Correct 6 ms 9676 KB Output is correct
49 Correct 6 ms 9676 KB Output is correct
50 Correct 6 ms 9676 KB Output is correct
51 Correct 6 ms 9676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 12 ms 10752 KB Output is correct
3 Correct 123 ms 19696 KB Output is correct
4 Correct 118 ms 19648 KB Output is correct
5 Correct 119 ms 19624 KB Output is correct
6 Correct 101 ms 19712 KB Output is correct
7 Correct 141 ms 27080 KB Output is correct
8 Correct 139 ms 24436 KB Output is correct
9 Correct 113 ms 24632 KB Output is correct
10 Correct 98 ms 20292 KB Output is correct
11 Correct 107 ms 19604 KB Output is correct
12 Correct 119 ms 19232 KB Output is correct
13 Correct 133 ms 19084 KB Output is correct
14 Correct 101 ms 22884 KB Output is correct
15 Correct 146 ms 28260 KB Output is correct
16 Correct 123 ms 29256 KB Output is correct
17 Correct 114 ms 19172 KB Output is correct
18 Correct 143 ms 19144 KB Output is correct
19 Correct 108 ms 19140 KB Output is correct
20 Correct 82 ms 19804 KB Output is correct
21 Correct 97 ms 19928 KB Output is correct
22 Correct 97 ms 19908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 6 ms 9676 KB Output is correct
3 Correct 6 ms 9676 KB Output is correct
4 Correct 7 ms 9676 KB Output is correct
5 Correct 6 ms 9676 KB Output is correct
6 Correct 6 ms 9752 KB Output is correct
7 Correct 7 ms 9676 KB Output is correct
8 Correct 6 ms 9676 KB Output is correct
9 Correct 7 ms 9676 KB Output is correct
10 Correct 7 ms 9676 KB Output is correct
11 Correct 6 ms 9676 KB Output is correct
12 Correct 6 ms 9676 KB Output is correct
13 Correct 6 ms 9676 KB Output is correct
14 Correct 5 ms 9676 KB Output is correct
15 Correct 6 ms 9752 KB Output is correct
16 Correct 6 ms 9744 KB Output is correct
17 Correct 6 ms 9676 KB Output is correct
18 Correct 6 ms 9676 KB Output is correct
19 Correct 6 ms 9676 KB Output is correct
20 Correct 5 ms 9676 KB Output is correct
21 Correct 5 ms 9676 KB Output is correct
22 Correct 6 ms 9676 KB Output is correct
23 Correct 6 ms 9676 KB Output is correct
24 Correct 6 ms 9708 KB Output is correct
25 Correct 6 ms 9676 KB Output is correct
26 Correct 7 ms 9676 KB Output is correct
27 Correct 6 ms 9676 KB Output is correct
28 Correct 6 ms 9676 KB Output is correct
29 Correct 6 ms 9676 KB Output is correct
30 Correct 6 ms 9664 KB Output is correct
31 Correct 6 ms 9676 KB Output is correct
32 Correct 6 ms 9676 KB Output is correct
33 Correct 6 ms 9676 KB Output is correct
34 Correct 6 ms 9680 KB Output is correct
35 Correct 6 ms 9676 KB Output is correct
36 Correct 6 ms 9676 KB Output is correct
37 Correct 6 ms 9676 KB Output is correct
38 Correct 8 ms 9676 KB Output is correct
39 Correct 6 ms 9676 KB Output is correct
40 Correct 6 ms 9664 KB Output is correct
41 Correct 6 ms 9676 KB Output is correct
42 Correct 6 ms 9692 KB Output is correct
43 Correct 6 ms 9676 KB Output is correct
44 Correct 6 ms 9676 KB Output is correct
45 Correct 6 ms 9684 KB Output is correct
46 Correct 6 ms 9676 KB Output is correct
47 Correct 6 ms 9676 KB Output is correct
48 Correct 6 ms 9676 KB Output is correct
49 Correct 6 ms 9676 KB Output is correct
50 Correct 6 ms 9676 KB Output is correct
51 Correct 6 ms 9676 KB Output is correct
52 Correct 8 ms 10188 KB Output is correct
53 Correct 8 ms 10244 KB Output is correct
54 Correct 9 ms 10188 KB Output is correct
55 Correct 9 ms 10252 KB Output is correct
56 Correct 10 ms 10572 KB Output is correct
57 Correct 9 ms 10188 KB Output is correct
58 Correct 10 ms 10316 KB Output is correct
59 Correct 9 ms 10372 KB Output is correct
60 Correct 8 ms 10324 KB Output is correct
61 Correct 9 ms 10188 KB Output is correct
62 Correct 9 ms 10188 KB Output is correct
63 Correct 8 ms 10316 KB Output is correct
64 Correct 8 ms 10244 KB Output is correct
65 Correct 9 ms 10188 KB Output is correct
66 Correct 9 ms 10188 KB Output is correct
67 Correct 8 ms 10316 KB Output is correct
68 Correct 9 ms 10444 KB Output is correct
69 Correct 9 ms 10188 KB Output is correct
70 Correct 8 ms 10316 KB Output is correct
71 Correct 10 ms 10188 KB Output is correct
72 Correct 9 ms 10188 KB Output is correct
73 Correct 8 ms 10316 KB Output is correct
74 Correct 10 ms 10188 KB Output is correct
75 Correct 9 ms 10428 KB Output is correct
76 Correct 11 ms 10188 KB Output is correct
77 Correct 10 ms 10508 KB Output is correct
78 Correct 9 ms 10244 KB Output is correct
79 Correct 9 ms 10444 KB Output is correct
80 Correct 9 ms 10188 KB Output is correct
81 Correct 9 ms 10188 KB Output is correct
82 Correct 8 ms 10188 KB Output is correct
83 Correct 8 ms 10248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 6 ms 9676 KB Output is correct
3 Correct 6 ms 9676 KB Output is correct
4 Correct 7 ms 9676 KB Output is correct
5 Correct 6 ms 9676 KB Output is correct
6 Correct 6 ms 9752 KB Output is correct
7 Correct 7 ms 9676 KB Output is correct
8 Correct 6 ms 9676 KB Output is correct
9 Correct 7 ms 9676 KB Output is correct
10 Correct 7 ms 9676 KB Output is correct
11 Correct 6 ms 9676 KB Output is correct
12 Correct 6 ms 9676 KB Output is correct
13 Correct 6 ms 9676 KB Output is correct
14 Correct 5 ms 9676 KB Output is correct
15 Correct 6 ms 9752 KB Output is correct
16 Correct 6 ms 9744 KB Output is correct
17 Correct 6 ms 9676 KB Output is correct
18 Correct 6 ms 9676 KB Output is correct
19 Correct 6 ms 9676 KB Output is correct
20 Correct 5 ms 9676 KB Output is correct
21 Correct 5 ms 9676 KB Output is correct
22 Correct 6 ms 9676 KB Output is correct
23 Correct 6 ms 9676 KB Output is correct
24 Correct 6 ms 9708 KB Output is correct
25 Correct 6 ms 9676 KB Output is correct
26 Correct 7 ms 9676 KB Output is correct
27 Correct 6 ms 9676 KB Output is correct
28 Correct 6 ms 9676 KB Output is correct
29 Correct 6 ms 9676 KB Output is correct
30 Correct 6 ms 9664 KB Output is correct
31 Correct 6 ms 9676 KB Output is correct
32 Correct 6 ms 9676 KB Output is correct
33 Correct 6 ms 9676 KB Output is correct
34 Correct 6 ms 9680 KB Output is correct
35 Correct 6 ms 9676 KB Output is correct
36 Correct 6 ms 9676 KB Output is correct
37 Correct 6 ms 9676 KB Output is correct
38 Correct 8 ms 9676 KB Output is correct
39 Correct 6 ms 9676 KB Output is correct
40 Correct 6 ms 9664 KB Output is correct
41 Correct 6 ms 9676 KB Output is correct
42 Correct 6 ms 9692 KB Output is correct
43 Correct 6 ms 9676 KB Output is correct
44 Correct 6 ms 9676 KB Output is correct
45 Correct 6 ms 9684 KB Output is correct
46 Correct 6 ms 9676 KB Output is correct
47 Correct 6 ms 9676 KB Output is correct
48 Correct 6 ms 9676 KB Output is correct
49 Correct 6 ms 9676 KB Output is correct
50 Correct 6 ms 9676 KB Output is correct
51 Correct 6 ms 9676 KB Output is correct
52 Correct 6 ms 9676 KB Output is correct
53 Correct 12 ms 10752 KB Output is correct
54 Correct 123 ms 19696 KB Output is correct
55 Correct 118 ms 19648 KB Output is correct
56 Correct 119 ms 19624 KB Output is correct
57 Correct 101 ms 19712 KB Output is correct
58 Correct 141 ms 27080 KB Output is correct
59 Correct 139 ms 24436 KB Output is correct
60 Correct 113 ms 24632 KB Output is correct
61 Correct 98 ms 20292 KB Output is correct
62 Correct 107 ms 19604 KB Output is correct
63 Correct 119 ms 19232 KB Output is correct
64 Correct 133 ms 19084 KB Output is correct
65 Correct 101 ms 22884 KB Output is correct
66 Correct 146 ms 28260 KB Output is correct
67 Correct 123 ms 29256 KB Output is correct
68 Correct 114 ms 19172 KB Output is correct
69 Correct 143 ms 19144 KB Output is correct
70 Correct 108 ms 19140 KB Output is correct
71 Correct 82 ms 19804 KB Output is correct
72 Correct 97 ms 19928 KB Output is correct
73 Correct 97 ms 19908 KB Output is correct
74 Correct 8 ms 10188 KB Output is correct
75 Correct 8 ms 10244 KB Output is correct
76 Correct 9 ms 10188 KB Output is correct
77 Correct 9 ms 10252 KB Output is correct
78 Correct 10 ms 10572 KB Output is correct
79 Correct 9 ms 10188 KB Output is correct
80 Correct 10 ms 10316 KB Output is correct
81 Correct 9 ms 10372 KB Output is correct
82 Correct 8 ms 10324 KB Output is correct
83 Correct 9 ms 10188 KB Output is correct
84 Correct 9 ms 10188 KB Output is correct
85 Correct 8 ms 10316 KB Output is correct
86 Correct 8 ms 10244 KB Output is correct
87 Correct 9 ms 10188 KB Output is correct
88 Correct 9 ms 10188 KB Output is correct
89 Correct 8 ms 10316 KB Output is correct
90 Correct 9 ms 10444 KB Output is correct
91 Correct 9 ms 10188 KB Output is correct
92 Correct 8 ms 10316 KB Output is correct
93 Correct 10 ms 10188 KB Output is correct
94 Correct 9 ms 10188 KB Output is correct
95 Correct 8 ms 10316 KB Output is correct
96 Correct 10 ms 10188 KB Output is correct
97 Correct 9 ms 10428 KB Output is correct
98 Correct 11 ms 10188 KB Output is correct
99 Correct 10 ms 10508 KB Output is correct
100 Correct 9 ms 10244 KB Output is correct
101 Correct 9 ms 10444 KB Output is correct
102 Correct 9 ms 10188 KB Output is correct
103 Correct 9 ms 10188 KB Output is correct
104 Correct 8 ms 10188 KB Output is correct
105 Correct 8 ms 10248 KB Output is correct
106 Correct 126 ms 20652 KB Output is correct
107 Correct 120 ms 20784 KB Output is correct
108 Correct 114 ms 20600 KB Output is correct
109 Correct 113 ms 20532 KB Output is correct
110 Correct 84 ms 21220 KB Output is correct
111 Correct 109 ms 22104 KB Output is correct
112 Correct 134 ms 26048 KB Output is correct
113 Correct 100 ms 19416 KB Output is correct
114 Correct 133 ms 19984 KB Output is correct
115 Correct 83 ms 20980 KB Output is correct
116 Correct 114 ms 26692 KB Output is correct
117 Correct 141 ms 25684 KB Output is correct
118 Correct 81 ms 21700 KB Output is correct
119 Correct 95 ms 19524 KB Output is correct
120 Correct 100 ms 19780 KB Output is correct
121 Correct 113 ms 19908 KB Output is correct
122 Correct 106 ms 19828 KB Output is correct
123 Correct 115 ms 21216 KB Output is correct
124 Correct 99 ms 21228 KB Output is correct
125 Correct 78 ms 21048 KB Output is correct
126 Correct 125 ms 20848 KB Output is correct
127 Correct 118 ms 20592 KB Output is correct
128 Correct 120 ms 20548 KB Output is correct
129 Correct 107 ms 20540 KB Output is correct
130 Correct 93 ms 21176 KB Output is correct
131 Correct 94 ms 22304 KB Output is correct
132 Correct 116 ms 25796 KB Output is correct
133 Correct 139 ms 19480 KB Output is correct
134 Correct 124 ms 19984 KB Output is correct
135 Correct 92 ms 20956 KB Output is correct
136 Correct 118 ms 24884 KB Output is correct
137 Correct 113 ms 25416 KB Output is correct
138 Correct 87 ms 21732 KB Output is correct
139 Incorrect 110 ms 19584 KB Output isn't correct
140 Halted 0 ms 0 KB -