#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3F3F3F3F3F3F3F3F
const int MXN = 1e5 + 5;
const int LOG = 20;
const int mod = 1e9 + 7;
vector<int> adj[MXN];
vector<array<int, 2>> g[MXN];
int p[MXN], used[MXN], down[MXN], bak[MXN];
int in[MXN], t[MXN], tim;
int dp[MXN];
void _init(int a)
{
t[a] = ++tim;
used[a] = 1;
for (array<int, 2> &v : g[a])
{
if (v[0] != p[a] && used[v[0]]) bak[v[1]] = 1;
}
for (array<int, 2> &v : g[a])
{
if (!used[v[0]])
{
p[v[0]] = a;
_init(v[0]);
}
}
}
void dfs(int a)
{
for (int &v : adj[a])
{
dfs(v);
}
if (down[a])
{
vector<int> path;
int x = down[a];
while (x)
{
path.push_back(x);
in[x] = 1;
if (x == a) break;
else assert(!down[x]);
x = p[x];
}
reverse(path.begin(), path.end());
vector<int> sum(path.size(), 0);
int co = 1;
for (int i = (int)path.size() - 1; i >= 0; i--)
{
if (i == (int)path.size() - 1) co = (co * dp[path[i]]) % mod;
else
{
for (int &v : adj[path[i]])
{
if (!in[v] && v != p[path[i]])
{
co = (co * (dp[v] + 1)) % mod;
}
}
}
sum[i] = ((i + 1 < path.size() ? sum[i + 1] : 0) + co) % mod;
}
co = 1;
for (int i = 0; i + 1 < path.size(); i++)
{
for (int &v : adj[path[i]])
{
if (!in[v] && v != p[path[i]])
{
co = (co * (dp[v] + 1)) % mod;
}
}
dp[a] = (dp[a] + co) % mod;
if (i + 2 < path.size()) dp[a] = (dp[a] + ((sum[i + 2] * co) % mod)) % mod;
}
for (int x : path) in[x] = 0;
}
else
{
dp[a] = 1;
for (int &v : adj[a])
{
dp[a] = (dp[a] * (dp[v] + 1)) % mod;
}
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
int u, v;
cin >> u >> v;
g[u].push_back({v, i});
g[v].push_back({u, i});
}
_init(1);
for (int a = 1; a <= n; a++)
{
for (array<int, 2> &v : g[a])
{
if (t[v[0]] > t[a] && !bak[v[1]]) adj[a].push_back(v[0]);
else if (t[v[0]] > t[a] && bak[v[1]]) down[a] = v[0];
}
}
dfs(1);
int res = 0;
for (int i = 1; i <= n; i++)
{
res = (res + dp[i]) % mod;
}
cout << res << '\n';
}
// 82 147 20 3 2 1 6 2 1 1 4 1 1
// 1 2 3 4 5 6 7 8 9 10 11 12 13
// 70 147 20 3 2 1 6 2 1 1 4 1 1
Compilation message
Main.cpp: In function 'void dfs(long long int)':
Main.cpp:70:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | sum[i] = ((i + 1 < path.size() ? sum[i + 1] : 0) + co) % mod;
| ~~~~~~^~~~~~~~~~~~~
Main.cpp:73:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int i = 0; i + 1 < path.size(); i++)
| ~~~~~~^~~~~~~~~~~~~
Main.cpp:83:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | if (i + 2 < path.size()) dp[a] = (dp[a] + ((sum[i + 2] * co) % mod)) % mod;
| ~~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
3 ms |
4996 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
5156 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
5156 KB |
Output is correct |
8 |
Correct |
2 ms |
5212 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
5160 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4952 KB |
Output is correct |
15 |
Correct |
2 ms |
5156 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
3 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
4956 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
29 |
Correct |
2 ms |
4956 KB |
Output is correct |
30 |
Correct |
2 ms |
5156 KB |
Output is correct |
31 |
Correct |
2 ms |
4956 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
2 ms |
4956 KB |
Output is correct |
34 |
Correct |
2 ms |
4956 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
5192 KB |
Output is correct |
40 |
Correct |
2 ms |
5156 KB |
Output is correct |
41 |
Correct |
2 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
3 ms |
5160 KB |
Output is correct |
44 |
Correct |
2 ms |
4956 KB |
Output is correct |
45 |
Correct |
2 ms |
4956 KB |
Output is correct |
46 |
Correct |
2 ms |
4956 KB |
Output is correct |
47 |
Correct |
2 ms |
4956 KB |
Output is correct |
48 |
Correct |
2 ms |
4956 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
50 |
Correct |
2 ms |
5160 KB |
Output is correct |
51 |
Correct |
2 ms |
5208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
5 ms |
6236 KB |
Output is correct |
3 |
Correct |
36 ms |
16340 KB |
Output is correct |
4 |
Correct |
43 ms |
16212 KB |
Output is correct |
5 |
Correct |
39 ms |
16220 KB |
Output is correct |
6 |
Correct |
38 ms |
16212 KB |
Output is correct |
7 |
Correct |
65 ms |
28500 KB |
Output is correct |
8 |
Correct |
47 ms |
23876 KB |
Output is correct |
9 |
Correct |
51 ms |
23504 KB |
Output is correct |
10 |
Correct |
27 ms |
15632 KB |
Output is correct |
11 |
Correct |
32 ms |
15808 KB |
Output is correct |
12 |
Correct |
48 ms |
17104 KB |
Output is correct |
13 |
Correct |
49 ms |
17492 KB |
Output is correct |
14 |
Correct |
39 ms |
20668 KB |
Output is correct |
15 |
Correct |
55 ms |
30020 KB |
Output is correct |
16 |
Correct |
58 ms |
32080 KB |
Output is correct |
17 |
Correct |
43 ms |
17444 KB |
Output is correct |
18 |
Correct |
44 ms |
17488 KB |
Output is correct |
19 |
Correct |
51 ms |
17604 KB |
Output is correct |
20 |
Correct |
30 ms |
15520 KB |
Output is correct |
21 |
Correct |
28 ms |
15060 KB |
Output is correct |
22 |
Correct |
26 ms |
14840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
3 ms |
4996 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
5156 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
5156 KB |
Output is correct |
8 |
Correct |
2 ms |
5212 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
5160 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4952 KB |
Output is correct |
15 |
Correct |
2 ms |
5156 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
3 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
4956 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
29 |
Correct |
2 ms |
4956 KB |
Output is correct |
30 |
Correct |
2 ms |
5156 KB |
Output is correct |
31 |
Correct |
2 ms |
4956 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
2 ms |
4956 KB |
Output is correct |
34 |
Correct |
2 ms |
4956 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
5192 KB |
Output is correct |
40 |
Correct |
2 ms |
5156 KB |
Output is correct |
41 |
Correct |
2 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
3 ms |
5160 KB |
Output is correct |
44 |
Correct |
2 ms |
4956 KB |
Output is correct |
45 |
Correct |
2 ms |
4956 KB |
Output is correct |
46 |
Correct |
2 ms |
4956 KB |
Output is correct |
47 |
Correct |
2 ms |
4956 KB |
Output is correct |
48 |
Correct |
2 ms |
4956 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
50 |
Correct |
2 ms |
5160 KB |
Output is correct |
51 |
Correct |
2 ms |
5208 KB |
Output is correct |
52 |
Correct |
4 ms |
5824 KB |
Output is correct |
53 |
Correct |
4 ms |
5724 KB |
Output is correct |
54 |
Correct |
4 ms |
5720 KB |
Output is correct |
55 |
Correct |
6 ms |
5720 KB |
Output is correct |
56 |
Correct |
7 ms |
6340 KB |
Output is correct |
57 |
Correct |
3 ms |
5572 KB |
Output is correct |
58 |
Correct |
3 ms |
5720 KB |
Output is correct |
59 |
Correct |
6 ms |
5980 KB |
Output is correct |
60 |
Correct |
3 ms |
5724 KB |
Output is correct |
61 |
Correct |
4 ms |
5812 KB |
Output is correct |
62 |
Correct |
7 ms |
5980 KB |
Output is correct |
63 |
Correct |
3 ms |
5468 KB |
Output is correct |
64 |
Correct |
3 ms |
5468 KB |
Output is correct |
65 |
Correct |
4 ms |
5684 KB |
Output is correct |
66 |
Correct |
7 ms |
5724 KB |
Output is correct |
67 |
Correct |
3 ms |
5724 KB |
Output is correct |
68 |
Correct |
5 ms |
6236 KB |
Output is correct |
69 |
Correct |
4 ms |
5724 KB |
Output is correct |
70 |
Correct |
6 ms |
5724 KB |
Output is correct |
71 |
Correct |
5 ms |
5724 KB |
Output is correct |
72 |
Correct |
5 ms |
5980 KB |
Output is correct |
73 |
Correct |
6 ms |
5724 KB |
Output is correct |
74 |
Correct |
5 ms |
5888 KB |
Output is correct |
75 |
Correct |
5 ms |
6236 KB |
Output is correct |
76 |
Correct |
5 ms |
5724 KB |
Output is correct |
77 |
Correct |
5 ms |
6232 KB |
Output is correct |
78 |
Correct |
5 ms |
5980 KB |
Output is correct |
79 |
Correct |
5 ms |
6236 KB |
Output is correct |
80 |
Correct |
6 ms |
5828 KB |
Output is correct |
81 |
Correct |
4 ms |
5684 KB |
Output is correct |
82 |
Correct |
4 ms |
5724 KB |
Output is correct |
83 |
Correct |
4 ms |
5684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
3 ms |
4996 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
5156 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
5156 KB |
Output is correct |
8 |
Correct |
2 ms |
5212 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
5160 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
2 ms |
4952 KB |
Output is correct |
15 |
Correct |
2 ms |
5156 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
3 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
4956 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
29 |
Correct |
2 ms |
4956 KB |
Output is correct |
30 |
Correct |
2 ms |
5156 KB |
Output is correct |
31 |
Correct |
2 ms |
4956 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
2 ms |
4956 KB |
Output is correct |
34 |
Correct |
2 ms |
4956 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
5192 KB |
Output is correct |
40 |
Correct |
2 ms |
5156 KB |
Output is correct |
41 |
Correct |
2 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
3 ms |
5160 KB |
Output is correct |
44 |
Correct |
2 ms |
4956 KB |
Output is correct |
45 |
Correct |
2 ms |
4956 KB |
Output is correct |
46 |
Correct |
2 ms |
4956 KB |
Output is correct |
47 |
Correct |
2 ms |
4956 KB |
Output is correct |
48 |
Correct |
2 ms |
4956 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
50 |
Correct |
2 ms |
5160 KB |
Output is correct |
51 |
Correct |
2 ms |
5208 KB |
Output is correct |
52 |
Correct |
2 ms |
4956 KB |
Output is correct |
53 |
Correct |
5 ms |
6236 KB |
Output is correct |
54 |
Correct |
36 ms |
16340 KB |
Output is correct |
55 |
Correct |
43 ms |
16212 KB |
Output is correct |
56 |
Correct |
39 ms |
16220 KB |
Output is correct |
57 |
Correct |
38 ms |
16212 KB |
Output is correct |
58 |
Correct |
65 ms |
28500 KB |
Output is correct |
59 |
Correct |
47 ms |
23876 KB |
Output is correct |
60 |
Correct |
51 ms |
23504 KB |
Output is correct |
61 |
Correct |
27 ms |
15632 KB |
Output is correct |
62 |
Correct |
32 ms |
15808 KB |
Output is correct |
63 |
Correct |
48 ms |
17104 KB |
Output is correct |
64 |
Correct |
49 ms |
17492 KB |
Output is correct |
65 |
Correct |
39 ms |
20668 KB |
Output is correct |
66 |
Correct |
55 ms |
30020 KB |
Output is correct |
67 |
Correct |
58 ms |
32080 KB |
Output is correct |
68 |
Correct |
43 ms |
17444 KB |
Output is correct |
69 |
Correct |
44 ms |
17488 KB |
Output is correct |
70 |
Correct |
51 ms |
17604 KB |
Output is correct |
71 |
Correct |
30 ms |
15520 KB |
Output is correct |
72 |
Correct |
28 ms |
15060 KB |
Output is correct |
73 |
Correct |
26 ms |
14840 KB |
Output is correct |
74 |
Correct |
4 ms |
5824 KB |
Output is correct |
75 |
Correct |
4 ms |
5724 KB |
Output is correct |
76 |
Correct |
4 ms |
5720 KB |
Output is correct |
77 |
Correct |
6 ms |
5720 KB |
Output is correct |
78 |
Correct |
7 ms |
6340 KB |
Output is correct |
79 |
Correct |
3 ms |
5572 KB |
Output is correct |
80 |
Correct |
3 ms |
5720 KB |
Output is correct |
81 |
Correct |
6 ms |
5980 KB |
Output is correct |
82 |
Correct |
3 ms |
5724 KB |
Output is correct |
83 |
Correct |
4 ms |
5812 KB |
Output is correct |
84 |
Correct |
7 ms |
5980 KB |
Output is correct |
85 |
Correct |
3 ms |
5468 KB |
Output is correct |
86 |
Correct |
3 ms |
5468 KB |
Output is correct |
87 |
Correct |
4 ms |
5684 KB |
Output is correct |
88 |
Correct |
7 ms |
5724 KB |
Output is correct |
89 |
Correct |
3 ms |
5724 KB |
Output is correct |
90 |
Correct |
5 ms |
6236 KB |
Output is correct |
91 |
Correct |
4 ms |
5724 KB |
Output is correct |
92 |
Correct |
6 ms |
5724 KB |
Output is correct |
93 |
Correct |
5 ms |
5724 KB |
Output is correct |
94 |
Correct |
5 ms |
5980 KB |
Output is correct |
95 |
Correct |
6 ms |
5724 KB |
Output is correct |
96 |
Correct |
5 ms |
5888 KB |
Output is correct |
97 |
Correct |
5 ms |
6236 KB |
Output is correct |
98 |
Correct |
5 ms |
5724 KB |
Output is correct |
99 |
Correct |
5 ms |
6232 KB |
Output is correct |
100 |
Correct |
5 ms |
5980 KB |
Output is correct |
101 |
Correct |
5 ms |
6236 KB |
Output is correct |
102 |
Correct |
6 ms |
5828 KB |
Output is correct |
103 |
Correct |
4 ms |
5684 KB |
Output is correct |
104 |
Correct |
4 ms |
5724 KB |
Output is correct |
105 |
Correct |
4 ms |
5684 KB |
Output is correct |
106 |
Runtime error |
63 ms |
35704 KB |
Execution killed with signal 6 |
107 |
Halted |
0 ms |
0 KB |
- |