#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 12, mod = 1e9 + 7;
long long n, m, pd[maxn], h[maxn], dp[maxn], sum[maxn];
vector <int> conn[maxn], nums;
bitset <maxn> marked, in_nums;
void dfs(int u, int p = -1){
marked[u] = 1;
int me = -1;
for(int v: conn[u])
if(!marked[v]){
pd[v] = u;
h[v] = h[u] + 1;
dfs(v, u);
}
else if(h[u] < h[v])
me = v;
// cout << u << ' ' << me << endl;
if(me == -1){
dp[u] = 1;
for(int v: conn[u])
if(h[u] < h[v]){
// cout << u << '-' << v << endl;
dp[u] = (dp[u] * (dp[v] + 1)) % mod;
}
dp[u] %= mod;
//cout << u << "->" << dp[u] << endl;
}
else{
nums.clear();
in_nums = 0;
while(h[u] <= h[me] && me){
nums.push_back(me);
in_nums[me] = 1;
me = pd[me];
}
for(int j = 0; j <= nums.size(); j++)
sum[j] = 0;
long long res = 1;
for(int j = 0; j < nums.size(); j++){
int nu = nums[j];
for(int v: conn[nu])
if(h[nu] < h[v] && !in_nums[v]){
res = res * (dp[v] + 1) % mod;
res %= mod;
}
sum[j] = (j == 0? 1: sum[j - 1]);
sum[j] += res;
sum[j] %= mod;
// cout << nu << ' ' << sum[j] << endl;
}
// cout << dp[2] << endl;
res = 1;
for(int j = nums.size() - 1; j >= 1; j--){
int nu = nums[j];
for(int v: conn[nu])
if(h[nu] < h[v] && !in_nums[v]){
res = res * (dp[v] + 1) % mod;
}
res %= mod;
if(j - 2 >= 0)
dp[u] += res % mod * (sum[j - 2] % mod) % mod;
dp[u] %= mod;
}
//cout << dp[2] << endl;
dp[u] += res;
dp[u] %= mod;
}
}
int main(){
cin >> n >> m;
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
conn[a].push_back(b);
conn[b].push_back(a);
}
// cout << endl;
dfs(1);
long long ans = 0;
// cout << endl;
for(int i = 1; i <= n; i++){
ans += dp[i];
ans %= mod;
// cout << i << ' ' << dp[i] << endl;
}
cout << ans << endl;
}
/* cin >> n >> m;
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
e[a][b] = 1;
e[b][a] = 1;
}
int ans = 0;
cout << endl;
for(int i = 0; i < (1 << n); i++){
for(int j = 0; j < n; j++)
if((i >> j) & 1)
p.push_back(j + 1);
int num = 0;
for(int j = 0; j < p.size(); j++)
for(int c = j; c < p.size(); c++)
if(e[p[j]][p[c]])
num += 1;
if(num == p.size() - 1){
if(p[0] == 1){
for(int j: p)
cout << j << ' ';
cout << endl;
}
ans += 1;
}
p.clear();
}
cout << ans << endl;
*/
Compilation message
Main.cpp: In function 'void dfs(int, int)':
Main.cpp:40:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int j = 0; j <= nums.size(); j++)
| ~~^~~~~~~~~~~~~~
Main.cpp:43:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int j = 0; j < nums.size(); j++){
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2772 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2664 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2772 KB |
Output is correct |
10 |
Correct |
1 ms |
2772 KB |
Output is correct |
11 |
Correct |
1 ms |
2772 KB |
Output is correct |
12 |
Correct |
1 ms |
2792 KB |
Output is correct |
13 |
Correct |
1 ms |
2772 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2772 KB |
Output is correct |
16 |
Correct |
1 ms |
2772 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
1 ms |
2772 KB |
Output is correct |
19 |
Correct |
2 ms |
2788 KB |
Output is correct |
20 |
Correct |
2 ms |
2772 KB |
Output is correct |
21 |
Correct |
1 ms |
2772 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
1 ms |
2644 KB |
Output is correct |
25 |
Correct |
1 ms |
2644 KB |
Output is correct |
26 |
Correct |
1 ms |
2644 KB |
Output is correct |
27 |
Correct |
1 ms |
2772 KB |
Output is correct |
28 |
Correct |
1 ms |
2772 KB |
Output is correct |
29 |
Correct |
1 ms |
2772 KB |
Output is correct |
30 |
Correct |
1 ms |
2772 KB |
Output is correct |
31 |
Correct |
1 ms |
2772 KB |
Output is correct |
32 |
Correct |
1 ms |
2772 KB |
Output is correct |
33 |
Correct |
1 ms |
2660 KB |
Output is correct |
34 |
Correct |
1 ms |
2772 KB |
Output is correct |
35 |
Correct |
1 ms |
2772 KB |
Output is correct |
36 |
Correct |
1 ms |
2772 KB |
Output is correct |
37 |
Correct |
1 ms |
2772 KB |
Output is correct |
38 |
Correct |
1 ms |
2792 KB |
Output is correct |
39 |
Correct |
2 ms |
2900 KB |
Output is correct |
40 |
Correct |
1 ms |
2900 KB |
Output is correct |
41 |
Correct |
1 ms |
2900 KB |
Output is correct |
42 |
Correct |
1 ms |
2644 KB |
Output is correct |
43 |
Correct |
1 ms |
2900 KB |
Output is correct |
44 |
Correct |
1 ms |
2772 KB |
Output is correct |
45 |
Correct |
1 ms |
2772 KB |
Output is correct |
46 |
Correct |
1 ms |
2772 KB |
Output is correct |
47 |
Correct |
1 ms |
2772 KB |
Output is correct |
48 |
Correct |
1 ms |
2900 KB |
Output is correct |
49 |
Correct |
2 ms |
2900 KB |
Output is correct |
50 |
Correct |
1 ms |
2900 KB |
Output is correct |
51 |
Correct |
1 ms |
2900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2792 KB |
Output is correct |
2 |
Correct |
7 ms |
3640 KB |
Output is correct |
3 |
Correct |
56 ms |
9704 KB |
Output is correct |
4 |
Correct |
65 ms |
9824 KB |
Output is correct |
5 |
Correct |
56 ms |
9832 KB |
Output is correct |
6 |
Correct |
55 ms |
9712 KB |
Output is correct |
7 |
Correct |
746 ms |
902880 KB |
Output is correct |
8 |
Correct |
315 ms |
573388 KB |
Output is correct |
9 |
Correct |
271 ms |
570188 KB |
Output is correct |
10 |
Correct |
52 ms |
10492 KB |
Output is correct |
11 |
Correct |
51 ms |
9620 KB |
Output is correct |
12 |
Correct |
59 ms |
9532 KB |
Output is correct |
13 |
Correct |
64 ms |
14796 KB |
Output is correct |
14 |
Correct |
184 ms |
380144 KB |
Output is correct |
15 |
Correct |
568 ms |
1035956 KB |
Output is correct |
16 |
Runtime error |
422 ms |
1048576 KB |
Execution killed with signal 9 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2772 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2664 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2772 KB |
Output is correct |
10 |
Correct |
1 ms |
2772 KB |
Output is correct |
11 |
Correct |
1 ms |
2772 KB |
Output is correct |
12 |
Correct |
1 ms |
2792 KB |
Output is correct |
13 |
Correct |
1 ms |
2772 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2772 KB |
Output is correct |
16 |
Correct |
1 ms |
2772 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
1 ms |
2772 KB |
Output is correct |
19 |
Correct |
2 ms |
2788 KB |
Output is correct |
20 |
Correct |
2 ms |
2772 KB |
Output is correct |
21 |
Correct |
1 ms |
2772 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
1 ms |
2644 KB |
Output is correct |
25 |
Correct |
1 ms |
2644 KB |
Output is correct |
26 |
Correct |
1 ms |
2644 KB |
Output is correct |
27 |
Correct |
1 ms |
2772 KB |
Output is correct |
28 |
Correct |
1 ms |
2772 KB |
Output is correct |
29 |
Correct |
1 ms |
2772 KB |
Output is correct |
30 |
Correct |
1 ms |
2772 KB |
Output is correct |
31 |
Correct |
1 ms |
2772 KB |
Output is correct |
32 |
Correct |
1 ms |
2772 KB |
Output is correct |
33 |
Correct |
1 ms |
2660 KB |
Output is correct |
34 |
Correct |
1 ms |
2772 KB |
Output is correct |
35 |
Correct |
1 ms |
2772 KB |
Output is correct |
36 |
Correct |
1 ms |
2772 KB |
Output is correct |
37 |
Correct |
1 ms |
2772 KB |
Output is correct |
38 |
Correct |
1 ms |
2792 KB |
Output is correct |
39 |
Correct |
2 ms |
2900 KB |
Output is correct |
40 |
Correct |
1 ms |
2900 KB |
Output is correct |
41 |
Correct |
1 ms |
2900 KB |
Output is correct |
42 |
Correct |
1 ms |
2644 KB |
Output is correct |
43 |
Correct |
1 ms |
2900 KB |
Output is correct |
44 |
Correct |
1 ms |
2772 KB |
Output is correct |
45 |
Correct |
1 ms |
2772 KB |
Output is correct |
46 |
Correct |
1 ms |
2772 KB |
Output is correct |
47 |
Correct |
1 ms |
2772 KB |
Output is correct |
48 |
Correct |
1 ms |
2900 KB |
Output is correct |
49 |
Correct |
2 ms |
2900 KB |
Output is correct |
50 |
Correct |
1 ms |
2900 KB |
Output is correct |
51 |
Correct |
1 ms |
2900 KB |
Output is correct |
52 |
Correct |
4 ms |
3412 KB |
Output is correct |
53 |
Correct |
4 ms |
3284 KB |
Output is correct |
54 |
Correct |
5 ms |
3312 KB |
Output is correct |
55 |
Correct |
5 ms |
5588 KB |
Output is correct |
56 |
Correct |
27 ms |
51440 KB |
Output is correct |
57 |
Correct |
5 ms |
3028 KB |
Output is correct |
58 |
Correct |
4 ms |
3060 KB |
Output is correct |
59 |
Correct |
12 ms |
22100 KB |
Output is correct |
60 |
Correct |
4 ms |
3400 KB |
Output is correct |
61 |
Correct |
5 ms |
5108 KB |
Output is correct |
62 |
Correct |
8 ms |
5076 KB |
Output is correct |
63 |
Correct |
4 ms |
3028 KB |
Output is correct |
64 |
Correct |
3 ms |
3028 KB |
Output is correct |
65 |
Correct |
4 ms |
3312 KB |
Output is correct |
66 |
Correct |
4 ms |
3412 KB |
Output is correct |
67 |
Correct |
5 ms |
5332 KB |
Output is correct |
68 |
Correct |
23 ms |
38900 KB |
Output is correct |
69 |
Correct |
4 ms |
3412 KB |
Output is correct |
70 |
Correct |
4 ms |
3540 KB |
Output is correct |
71 |
Correct |
6 ms |
5108 KB |
Output is correct |
72 |
Correct |
6 ms |
5236 KB |
Output is correct |
73 |
Correct |
4 ms |
3016 KB |
Output is correct |
74 |
Correct |
5 ms |
4308 KB |
Output is correct |
75 |
Correct |
16 ms |
28244 KB |
Output is correct |
76 |
Correct |
5 ms |
4692 KB |
Output is correct |
77 |
Correct |
23 ms |
44904 KB |
Output is correct |
78 |
Correct |
13 ms |
11760 KB |
Output is correct |
79 |
Correct |
20 ms |
40660 KB |
Output is correct |
80 |
Correct |
6 ms |
5936 KB |
Output is correct |
81 |
Correct |
6 ms |
8436 KB |
Output is correct |
82 |
Correct |
6 ms |
7924 KB |
Output is correct |
83 |
Correct |
5 ms |
5972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2772 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2664 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2772 KB |
Output is correct |
10 |
Correct |
1 ms |
2772 KB |
Output is correct |
11 |
Correct |
1 ms |
2772 KB |
Output is correct |
12 |
Correct |
1 ms |
2792 KB |
Output is correct |
13 |
Correct |
1 ms |
2772 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2772 KB |
Output is correct |
16 |
Correct |
1 ms |
2772 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
1 ms |
2772 KB |
Output is correct |
19 |
Correct |
2 ms |
2788 KB |
Output is correct |
20 |
Correct |
2 ms |
2772 KB |
Output is correct |
21 |
Correct |
1 ms |
2772 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
1 ms |
2644 KB |
Output is correct |
25 |
Correct |
1 ms |
2644 KB |
Output is correct |
26 |
Correct |
1 ms |
2644 KB |
Output is correct |
27 |
Correct |
1 ms |
2772 KB |
Output is correct |
28 |
Correct |
1 ms |
2772 KB |
Output is correct |
29 |
Correct |
1 ms |
2772 KB |
Output is correct |
30 |
Correct |
1 ms |
2772 KB |
Output is correct |
31 |
Correct |
1 ms |
2772 KB |
Output is correct |
32 |
Correct |
1 ms |
2772 KB |
Output is correct |
33 |
Correct |
1 ms |
2660 KB |
Output is correct |
34 |
Correct |
1 ms |
2772 KB |
Output is correct |
35 |
Correct |
1 ms |
2772 KB |
Output is correct |
36 |
Correct |
1 ms |
2772 KB |
Output is correct |
37 |
Correct |
1 ms |
2772 KB |
Output is correct |
38 |
Correct |
1 ms |
2792 KB |
Output is correct |
39 |
Correct |
2 ms |
2900 KB |
Output is correct |
40 |
Correct |
1 ms |
2900 KB |
Output is correct |
41 |
Correct |
1 ms |
2900 KB |
Output is correct |
42 |
Correct |
1 ms |
2644 KB |
Output is correct |
43 |
Correct |
1 ms |
2900 KB |
Output is correct |
44 |
Correct |
1 ms |
2772 KB |
Output is correct |
45 |
Correct |
1 ms |
2772 KB |
Output is correct |
46 |
Correct |
1 ms |
2772 KB |
Output is correct |
47 |
Correct |
1 ms |
2772 KB |
Output is correct |
48 |
Correct |
1 ms |
2900 KB |
Output is correct |
49 |
Correct |
2 ms |
2900 KB |
Output is correct |
50 |
Correct |
1 ms |
2900 KB |
Output is correct |
51 |
Correct |
1 ms |
2900 KB |
Output is correct |
52 |
Correct |
1 ms |
2792 KB |
Output is correct |
53 |
Correct |
7 ms |
3640 KB |
Output is correct |
54 |
Correct |
56 ms |
9704 KB |
Output is correct |
55 |
Correct |
65 ms |
9824 KB |
Output is correct |
56 |
Correct |
56 ms |
9832 KB |
Output is correct |
57 |
Correct |
55 ms |
9712 KB |
Output is correct |
58 |
Correct |
746 ms |
902880 KB |
Output is correct |
59 |
Correct |
315 ms |
573388 KB |
Output is correct |
60 |
Correct |
271 ms |
570188 KB |
Output is correct |
61 |
Correct |
52 ms |
10492 KB |
Output is correct |
62 |
Correct |
51 ms |
9620 KB |
Output is correct |
63 |
Correct |
59 ms |
9532 KB |
Output is correct |
64 |
Correct |
64 ms |
14796 KB |
Output is correct |
65 |
Correct |
184 ms |
380144 KB |
Output is correct |
66 |
Correct |
568 ms |
1035956 KB |
Output is correct |
67 |
Runtime error |
422 ms |
1048576 KB |
Execution killed with signal 9 |
68 |
Halted |
0 ms |
0 KB |
- |