답안 #469049

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469049 2021-08-30T14:05:05 Z alirezasamimi100 Subtree (INOI20_subtree) C++17
100 / 100
131 ms 29296 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]+dd[i+1])%MOD;
    }
    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 5 ms 9676 KB Output is correct
4 Correct 6 ms 9676 KB Output is correct
5 Correct 6 ms 9676 KB Output is correct
6 Correct 6 ms 9676 KB Output is correct
7 Correct 6 ms 9676 KB Output is correct
8 Correct 6 ms 9668 KB Output is correct
9 Correct 6 ms 9676 KB Output is correct
10 Correct 6 ms 9676 KB Output is correct
11 Correct 5 ms 9676 KB Output is correct
12 Correct 5 ms 9676 KB Output is correct
13 Correct 7 ms 9676 KB Output is correct
14 Correct 5 ms 9664 KB Output is correct
15 Correct 6 ms 9676 KB Output is correct
16 Correct 5 ms 9676 KB Output is correct
17 Correct 6 ms 9676 KB Output is correct
18 Correct 6 ms 9704 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 5 ms 9676 KB Output is correct
25 Correct 5 ms 9676 KB Output is correct
26 Correct 5 ms 9676 KB Output is correct
27 Correct 5 ms 9748 KB Output is correct
28 Correct 5 ms 9676 KB Output is correct
29 Correct 6 ms 9676 KB Output is correct
30 Correct 6 ms 9676 KB Output is correct
31 Correct 5 ms 9676 KB Output is correct
32 Correct 6 ms 9676 KB Output is correct
33 Correct 5 ms 9676 KB Output is correct
34 Correct 5 ms 9676 KB Output is correct
35 Correct 6 ms 9676 KB Output is correct
36 Correct 6 ms 9676 KB Output is correct
37 Correct 5 ms 9676 KB Output is correct
38 Correct 5 ms 9676 KB Output is correct
39 Correct 6 ms 9676 KB Output is correct
40 Correct 5 ms 9676 KB Output is correct
41 Correct 6 ms 9676 KB Output is correct
42 Correct 6 ms 9676 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 9676 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 7 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 11 ms 10748 KB Output is correct
3 Correct 97 ms 19728 KB Output is correct
4 Correct 107 ms 19700 KB Output is correct
5 Correct 121 ms 19656 KB Output is correct
6 Correct 101 ms 19716 KB Output is correct
7 Correct 127 ms 27104 KB Output is correct
8 Correct 122 ms 24440 KB Output is correct
9 Correct 111 ms 24668 KB Output is correct
10 Correct 90 ms 20472 KB Output is correct
11 Correct 88 ms 19608 KB Output is correct
12 Correct 130 ms 19100 KB Output is correct
13 Correct 131 ms 19116 KB Output is correct
14 Correct 94 ms 22968 KB Output is correct
15 Correct 131 ms 28228 KB Output is correct
16 Correct 124 ms 29296 KB Output is correct
17 Correct 109 ms 19140 KB Output is correct
18 Correct 110 ms 19280 KB Output is correct
19 Correct 110 ms 19224 KB Output is correct
20 Correct 78 ms 19920 KB Output is correct
21 Correct 81 ms 20024 KB Output is correct
22 Correct 82 ms 19900 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 5 ms 9676 KB Output is correct
4 Correct 6 ms 9676 KB Output is correct
5 Correct 6 ms 9676 KB Output is correct
6 Correct 6 ms 9676 KB Output is correct
7 Correct 6 ms 9676 KB Output is correct
8 Correct 6 ms 9668 KB Output is correct
9 Correct 6 ms 9676 KB Output is correct
10 Correct 6 ms 9676 KB Output is correct
11 Correct 5 ms 9676 KB Output is correct
12 Correct 5 ms 9676 KB Output is correct
13 Correct 7 ms 9676 KB Output is correct
14 Correct 5 ms 9664 KB Output is correct
15 Correct 6 ms 9676 KB Output is correct
16 Correct 5 ms 9676 KB Output is correct
17 Correct 6 ms 9676 KB Output is correct
18 Correct 6 ms 9704 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 5 ms 9676 KB Output is correct
25 Correct 5 ms 9676 KB Output is correct
26 Correct 5 ms 9676 KB Output is correct
27 Correct 5 ms 9748 KB Output is correct
28 Correct 5 ms 9676 KB Output is correct
29 Correct 6 ms 9676 KB Output is correct
30 Correct 6 ms 9676 KB Output is correct
31 Correct 5 ms 9676 KB Output is correct
32 Correct 6 ms 9676 KB Output is correct
33 Correct 5 ms 9676 KB Output is correct
34 Correct 5 ms 9676 KB Output is correct
35 Correct 6 ms 9676 KB Output is correct
36 Correct 6 ms 9676 KB Output is correct
37 Correct 5 ms 9676 KB Output is correct
38 Correct 5 ms 9676 KB Output is correct
39 Correct 6 ms 9676 KB Output is correct
40 Correct 5 ms 9676 KB Output is correct
41 Correct 6 ms 9676 KB Output is correct
42 Correct 6 ms 9676 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 9676 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 7 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 10236 KB Output is correct
53 Correct 8 ms 10240 KB Output is correct
54 Correct 8 ms 10232 KB Output is correct
55 Correct 8 ms 10188 KB Output is correct
56 Correct 9 ms 10620 KB Output is correct
57 Correct 9 ms 10188 KB Output is correct
58 Correct 8 ms 10188 KB Output is correct
59 Correct 8 ms 10408 KB Output is correct
60 Correct 8 ms 10188 KB Output is correct
61 Correct 8 ms 10188 KB Output is correct
62 Correct 9 ms 10160 KB Output is correct
63 Correct 8 ms 10272 KB Output is correct
64 Correct 8 ms 10188 KB Output is correct
65 Correct 8 ms 10188 KB Output is correct
66 Correct 9 ms 10188 KB Output is correct
67 Correct 8 ms 10188 KB Output is correct
68 Correct 9 ms 10444 KB Output is correct
69 Correct 8 ms 10188 KB Output is correct
70 Correct 9 ms 10188 KB Output is correct
71 Correct 9 ms 10192 KB Output is correct
72 Correct 9 ms 10188 KB Output is correct
73 Correct 8 ms 10188 KB Output is correct
74 Correct 8 ms 10116 KB Output is correct
75 Correct 9 ms 10316 KB Output is correct
76 Correct 9 ms 10260 KB Output is correct
77 Correct 9 ms 10444 KB Output is correct
78 Correct 9 ms 10216 KB Output is correct
79 Correct 8 ms 10444 KB Output is correct
80 Correct 9 ms 10188 KB Output is correct
81 Correct 8 ms 10216 KB Output is correct
82 Correct 8 ms 10188 KB Output is correct
83 Correct 8 ms 10188 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 5 ms 9676 KB Output is correct
4 Correct 6 ms 9676 KB Output is correct
5 Correct 6 ms 9676 KB Output is correct
6 Correct 6 ms 9676 KB Output is correct
7 Correct 6 ms 9676 KB Output is correct
8 Correct 6 ms 9668 KB Output is correct
9 Correct 6 ms 9676 KB Output is correct
10 Correct 6 ms 9676 KB Output is correct
11 Correct 5 ms 9676 KB Output is correct
12 Correct 5 ms 9676 KB Output is correct
13 Correct 7 ms 9676 KB Output is correct
14 Correct 5 ms 9664 KB Output is correct
15 Correct 6 ms 9676 KB Output is correct
16 Correct 5 ms 9676 KB Output is correct
17 Correct 6 ms 9676 KB Output is correct
18 Correct 6 ms 9704 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 5 ms 9676 KB Output is correct
25 Correct 5 ms 9676 KB Output is correct
26 Correct 5 ms 9676 KB Output is correct
27 Correct 5 ms 9748 KB Output is correct
28 Correct 5 ms 9676 KB Output is correct
29 Correct 6 ms 9676 KB Output is correct
30 Correct 6 ms 9676 KB Output is correct
31 Correct 5 ms 9676 KB Output is correct
32 Correct 6 ms 9676 KB Output is correct
33 Correct 5 ms 9676 KB Output is correct
34 Correct 5 ms 9676 KB Output is correct
35 Correct 6 ms 9676 KB Output is correct
36 Correct 6 ms 9676 KB Output is correct
37 Correct 5 ms 9676 KB Output is correct
38 Correct 5 ms 9676 KB Output is correct
39 Correct 6 ms 9676 KB Output is correct
40 Correct 5 ms 9676 KB Output is correct
41 Correct 6 ms 9676 KB Output is correct
42 Correct 6 ms 9676 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 9676 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 7 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 11 ms 10748 KB Output is correct
54 Correct 97 ms 19728 KB Output is correct
55 Correct 107 ms 19700 KB Output is correct
56 Correct 121 ms 19656 KB Output is correct
57 Correct 101 ms 19716 KB Output is correct
58 Correct 127 ms 27104 KB Output is correct
59 Correct 122 ms 24440 KB Output is correct
60 Correct 111 ms 24668 KB Output is correct
61 Correct 90 ms 20472 KB Output is correct
62 Correct 88 ms 19608 KB Output is correct
63 Correct 130 ms 19100 KB Output is correct
64 Correct 131 ms 19116 KB Output is correct
65 Correct 94 ms 22968 KB Output is correct
66 Correct 131 ms 28228 KB Output is correct
67 Correct 124 ms 29296 KB Output is correct
68 Correct 109 ms 19140 KB Output is correct
69 Correct 110 ms 19280 KB Output is correct
70 Correct 110 ms 19224 KB Output is correct
71 Correct 78 ms 19920 KB Output is correct
72 Correct 81 ms 20024 KB Output is correct
73 Correct 82 ms 19900 KB Output is correct
74 Correct 8 ms 10236 KB Output is correct
75 Correct 8 ms 10240 KB Output is correct
76 Correct 8 ms 10232 KB Output is correct
77 Correct 8 ms 10188 KB Output is correct
78 Correct 9 ms 10620 KB Output is correct
79 Correct 9 ms 10188 KB Output is correct
80 Correct 8 ms 10188 KB Output is correct
81 Correct 8 ms 10408 KB Output is correct
82 Correct 8 ms 10188 KB Output is correct
83 Correct 8 ms 10188 KB Output is correct
84 Correct 9 ms 10160 KB Output is correct
85 Correct 8 ms 10272 KB Output is correct
86 Correct 8 ms 10188 KB Output is correct
87 Correct 8 ms 10188 KB Output is correct
88 Correct 9 ms 10188 KB Output is correct
89 Correct 8 ms 10188 KB Output is correct
90 Correct 9 ms 10444 KB Output is correct
91 Correct 8 ms 10188 KB Output is correct
92 Correct 9 ms 10188 KB Output is correct
93 Correct 9 ms 10192 KB Output is correct
94 Correct 9 ms 10188 KB Output is correct
95 Correct 8 ms 10188 KB Output is correct
96 Correct 8 ms 10116 KB Output is correct
97 Correct 9 ms 10316 KB Output is correct
98 Correct 9 ms 10260 KB Output is correct
99 Correct 9 ms 10444 KB Output is correct
100 Correct 9 ms 10216 KB Output is correct
101 Correct 8 ms 10444 KB Output is correct
102 Correct 9 ms 10188 KB Output is correct
103 Correct 8 ms 10216 KB Output is correct
104 Correct 8 ms 10188 KB Output is correct
105 Correct 8 ms 10188 KB Output is correct
106 Correct 110 ms 19536 KB Output is correct
107 Correct 119 ms 19396 KB Output is correct
108 Correct 115 ms 19372 KB Output is correct
109 Correct 101 ms 19292 KB Output is correct
110 Correct 83 ms 19964 KB Output is correct
111 Correct 96 ms 20964 KB Output is correct
112 Correct 126 ms 24784 KB Output is correct
113 Correct 96 ms 18312 KB Output is correct
114 Correct 109 ms 18684 KB Output is correct
115 Correct 77 ms 19800 KB Output is correct
116 Correct 110 ms 25408 KB Output is correct
117 Correct 113 ms 24412 KB Output is correct
118 Correct 76 ms 20556 KB Output is correct
119 Correct 100 ms 18244 KB Output is correct
120 Correct 109 ms 18264 KB Output is correct
121 Correct 108 ms 18404 KB Output is correct
122 Correct 110 ms 18404 KB Output is correct
123 Correct 87 ms 20160 KB Output is correct
124 Correct 80 ms 20060 KB Output is correct
125 Correct 74 ms 19892 KB Output is correct
126 Correct 103 ms 19576 KB Output is correct
127 Correct 108 ms 19372 KB Output is correct
128 Correct 101 ms 19268 KB Output is correct
129 Correct 128 ms 19300 KB Output is correct
130 Correct 91 ms 20020 KB Output is correct
131 Correct 95 ms 20932 KB Output is correct
132 Correct 127 ms 24604 KB Output is correct
133 Correct 95 ms 18204 KB Output is correct
134 Correct 114 ms 18756 KB Output is correct
135 Correct 88 ms 19740 KB Output is correct
136 Correct 108 ms 23708 KB Output is correct
137 Correct 114 ms 24132 KB Output is correct
138 Correct 75 ms 20536 KB Output is correct
139 Correct 94 ms 18312 KB Output is correct
140 Correct 104 ms 19732 KB Output is correct
141 Correct 111 ms 19880 KB Output is correct
142 Correct 110 ms 19804 KB Output is correct
143 Correct 87 ms 21244 KB Output is correct
144 Correct 77 ms 21096 KB Output is correct
145 Correct 75 ms 21048 KB Output is correct
146 Correct 108 ms 19384 KB Output is correct
147 Correct 72 ms 18496 KB Output is correct
148 Correct 70 ms 18500 KB Output is correct
149 Correct 74 ms 19652 KB Output is correct
150 Correct 90 ms 27236 KB Output is correct
151 Correct 85 ms 19152 KB Output is correct
152 Correct 111 ms 20540 KB Output is correct
153 Correct 109 ms 20420 KB Output is correct
154 Correct 92 ms 20620 KB Output is correct
155 Correct 85 ms 21056 KB Output is correct
156 Correct 80 ms 24668 KB Output is correct
157 Correct 84 ms 23876 KB Output is correct
158 Correct 81 ms 22940 KB Output is correct
159 Correct 111 ms 20284 KB Output is correct
160 Correct 110 ms 27428 KB Output is correct
161 Correct 103 ms 20156 KB Output is correct
162 Correct 86 ms 21008 KB Output is correct