Submission #469105

# Submission time Handle Problem Language Result Execution time Memory
469105 2021-08-30T18:11:22 Z sinamhdv Subtree (INOI20_subtree) C++11
100 / 100
184 ms 27684 KB
// INOI20_subtree
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const ll LINF = 1e18 + 100;

#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define fast_io ios::sync_with_stdio(0); cin.tie(0);
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int MAXN = 100100;
const int MAXE = 150100;

int n, m;
vector<int> adj[MAXN];
int ef[MAXE], eto[MAXE];
int hei[MAXN];
bool iscut[MAXE];
bool mark[MAXN];
vector<int> comp[MAXN];
int cn, cnum[MAXN];
vector<int> tree[MAXN];
int head[MAXN], vpar[MAXN];
int dp[MAXN][2];
int wei[MAXN];

inline void addedge(int x, int y)
{
	tree[x].pb(y);
	tree[y].pb(x);
}

inline int dfs1(int v, int epar)
{
	mark[v] = true;
	int dp = hei[v];
	for (int e : adj[v]) if (e != epar)
	{
		int u = eto[e] ^ ef[e] ^ v;
		if (mark[u]) dp = min(dp, hei[u]);
		else hei[u] = hei[v] + 1, dp = min(dp, dfs1(u, e));
	}
	if (dp >= hei[v] && epar >= 0) iscut[epar] = true;
	return dp;
}

void dfs2(int v)
{
	cnum[v] = cn;
	comp[cn].pb(v);
	for (int e : adj[v]) if (!iscut[e])
	{
		int u = ef[e] ^ eto[e] ^ v;
		if (!cnum[u]) dfs2(u);
	}
}

void dfs3(int v)
{
	mark[v] = true;
	for (int e : adj[v])
	{
		int u = ef[e] ^ eto[e] ^ v;
		if (mark[u]) continue;
		if (iscut[e])
		{
			head[cnum[u]] = u;
			vpar[cnum[u]] = v;
		}
		dfs3(u);
	}
}

void dfs4(int v, int par)
{
	for (int u : tree[v]) if (u != par)
	{
		dfs4(u, v);
		wei[vpar[u]] = (wei[vpar[u]] * ((ll)dp[u][1] + 1)) % mod;
	}

	// calc dp
	if ((int)comp[v].size() == 1)	// single vertex
	{
		dp[v][0] = dp[v][1] = wei[comp[v][0]];
		return;
	}
	
	// cycle
	int k = (int)comp[v].size();
	vector<int> ps(k + 5);
	
	ps[0] = 0;
	int cur = 1;
	FOR(i, 1, k + 1)
	{
		cur = (ll)cur * wei[comp[v][i - 1]] % mod;
		ps[i] = (ps[i - 1] + cur) % mod;
	}

	cur = 1;
	for (int i = k - 1; i >= 1; i--)
	{
		dp[v][1] = (dp[v][1] + (ll)ps[i] * cur) % mod;
		cur = (ll)cur * wei[comp[v][i]] % mod;
	}

	dp[v][0] = dp[v][1];
	cur = 0;
	FOR(i, 1, k)
	{
		cur = wei[comp[v][i]] * ((ll)cur + 1) % mod;
		dp[v][0] = (dp[v][0] + cur) % mod;
	}
}

int32_t main(void)
{
	fast_io;
	cin >> n >> m;
	FOR(i, 0, m)
	{
		cin >> ef[i] >> eto[i];
		adj[ef[i]].pb(i);
		adj[eto[i]].pb(i);
	}

	dfs1(1, -1);
	
	FOR(i, 1, n + 1) if (!cnum[i]) cn++, dfs2(i);

	memset(mark, 0, sizeof(mark));
	dfs3(1);
	head[cnum[1]] = 1;

	FOR(i, 0, m) if (iscut[i]) addedge(cnum[ef[i]], cnum[eto[i]]);

	FOR(i, 1, cn + 1)
	{
		rotate(comp[i].begin(), find(all(comp[i]), head[i]), comp[i].end());
	}

	fill(wei + 1, wei + n + 1, 1);
	dfs4(cnum[1], -1);

	ll ans = 0;
	FOR(i, 1, cn + 1) ans = (ans + dp[i][0]) % mod;
	ans = (mod + ans % mod) % mod;
	cout << ans << endl;

	return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 4 ms 7500 KB Output is correct
2 Correct 4 ms 7500 KB Output is correct
3 Correct 4 ms 7500 KB Output is correct
4 Correct 4 ms 7500 KB Output is correct
5 Correct 4 ms 7500 KB Output is correct
6 Correct 4 ms 7500 KB Output is correct
7 Correct 5 ms 7500 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7500 KB Output is correct
10 Correct 5 ms 7500 KB Output is correct
11 Correct 6 ms 7500 KB Output is correct
12 Correct 4 ms 7512 KB Output is correct
13 Correct 4 ms 7500 KB Output is correct
14 Correct 4 ms 7500 KB Output is correct
15 Correct 5 ms 7408 KB Output is correct
16 Correct 4 ms 7500 KB Output is correct
17 Correct 4 ms 7500 KB Output is correct
18 Correct 5 ms 7500 KB Output is correct
19 Correct 5 ms 7500 KB Output is correct
20 Correct 4 ms 7500 KB Output is correct
21 Correct 4 ms 7500 KB Output is correct
22 Correct 4 ms 7500 KB Output is correct
23 Correct 4 ms 7500 KB Output is correct
24 Correct 4 ms 7500 KB Output is correct
25 Correct 4 ms 7500 KB Output is correct
26 Correct 5 ms 7500 KB Output is correct
27 Correct 4 ms 7500 KB Output is correct
28 Correct 4 ms 7500 KB Output is correct
29 Correct 5 ms 7440 KB Output is correct
30 Correct 6 ms 7500 KB Output is correct
31 Correct 5 ms 7500 KB Output is correct
32 Correct 5 ms 7500 KB Output is correct
33 Correct 4 ms 7500 KB Output is correct
34 Correct 4 ms 7500 KB Output is correct
35 Correct 4 ms 7500 KB Output is correct
36 Correct 4 ms 7500 KB Output is correct
37 Correct 4 ms 7500 KB Output is correct
38 Correct 4 ms 7500 KB Output is correct
39 Correct 4 ms 7500 KB Output is correct
40 Correct 4 ms 7372 KB Output is correct
41 Correct 6 ms 7500 KB Output is correct
42 Correct 4 ms 7432 KB Output is correct
43 Correct 4 ms 7500 KB Output is correct
44 Correct 5 ms 7500 KB Output is correct
45 Correct 4 ms 7500 KB Output is correct
46 Correct 4 ms 7500 KB Output is correct
47 Correct 4 ms 7500 KB Output is correct
48 Correct 4 ms 7500 KB Output is correct
49 Correct 4 ms 7372 KB Output is correct
50 Correct 4 ms 7500 KB Output is correct
51 Correct 5 ms 7500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7500 KB Output is correct
2 Correct 11 ms 8728 KB Output is correct
3 Correct 113 ms 20676 KB Output is correct
4 Correct 119 ms 20736 KB Output is correct
5 Correct 121 ms 20584 KB Output is correct
6 Correct 149 ms 20672 KB Output is correct
7 Correct 158 ms 26064 KB Output is correct
8 Correct 131 ms 23968 KB Output is correct
9 Correct 129 ms 24044 KB Output is correct
10 Correct 96 ms 21608 KB Output is correct
11 Correct 98 ms 21048 KB Output is correct
12 Correct 134 ms 20548 KB Output is correct
13 Correct 133 ms 20456 KB Output is correct
14 Correct 109 ms 23484 KB Output is correct
15 Correct 155 ms 27144 KB Output is correct
16 Correct 132 ms 27684 KB Output is correct
17 Correct 121 ms 20420 KB Output is correct
18 Correct 184 ms 20540 KB Output is correct
19 Correct 142 ms 20644 KB Output is correct
20 Correct 94 ms 21304 KB Output is correct
21 Correct 91 ms 21364 KB Output is correct
22 Correct 92 ms 21224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7500 KB Output is correct
2 Correct 4 ms 7500 KB Output is correct
3 Correct 4 ms 7500 KB Output is correct
4 Correct 4 ms 7500 KB Output is correct
5 Correct 4 ms 7500 KB Output is correct
6 Correct 4 ms 7500 KB Output is correct
7 Correct 5 ms 7500 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7500 KB Output is correct
10 Correct 5 ms 7500 KB Output is correct
11 Correct 6 ms 7500 KB Output is correct
12 Correct 4 ms 7512 KB Output is correct
13 Correct 4 ms 7500 KB Output is correct
14 Correct 4 ms 7500 KB Output is correct
15 Correct 5 ms 7408 KB Output is correct
16 Correct 4 ms 7500 KB Output is correct
17 Correct 4 ms 7500 KB Output is correct
18 Correct 5 ms 7500 KB Output is correct
19 Correct 5 ms 7500 KB Output is correct
20 Correct 4 ms 7500 KB Output is correct
21 Correct 4 ms 7500 KB Output is correct
22 Correct 4 ms 7500 KB Output is correct
23 Correct 4 ms 7500 KB Output is correct
24 Correct 4 ms 7500 KB Output is correct
25 Correct 4 ms 7500 KB Output is correct
26 Correct 5 ms 7500 KB Output is correct
27 Correct 4 ms 7500 KB Output is correct
28 Correct 4 ms 7500 KB Output is correct
29 Correct 5 ms 7440 KB Output is correct
30 Correct 6 ms 7500 KB Output is correct
31 Correct 5 ms 7500 KB Output is correct
32 Correct 5 ms 7500 KB Output is correct
33 Correct 4 ms 7500 KB Output is correct
34 Correct 4 ms 7500 KB Output is correct
35 Correct 4 ms 7500 KB Output is correct
36 Correct 4 ms 7500 KB Output is correct
37 Correct 4 ms 7500 KB Output is correct
38 Correct 4 ms 7500 KB Output is correct
39 Correct 4 ms 7500 KB Output is correct
40 Correct 4 ms 7372 KB Output is correct
41 Correct 6 ms 7500 KB Output is correct
42 Correct 4 ms 7432 KB Output is correct
43 Correct 4 ms 7500 KB Output is correct
44 Correct 5 ms 7500 KB Output is correct
45 Correct 4 ms 7500 KB Output is correct
46 Correct 4 ms 7500 KB Output is correct
47 Correct 4 ms 7500 KB Output is correct
48 Correct 4 ms 7500 KB Output is correct
49 Correct 4 ms 7372 KB Output is correct
50 Correct 4 ms 7500 KB Output is correct
51 Correct 5 ms 7500 KB Output is correct
52 Correct 8 ms 8012 KB Output is correct
53 Correct 8 ms 8012 KB Output is correct
54 Correct 8 ms 8012 KB Output is correct
55 Correct 8 ms 8140 KB Output is correct
56 Correct 8 ms 8140 KB Output is correct
57 Correct 8 ms 8140 KB Output is correct
58 Correct 7 ms 8140 KB Output is correct
59 Correct 8 ms 8140 KB Output is correct
60 Correct 8 ms 8140 KB Output is correct
61 Correct 8 ms 8012 KB Output is correct
62 Correct 8 ms 7844 KB Output is correct
63 Correct 7 ms 8140 KB Output is correct
64 Correct 7 ms 8140 KB Output is correct
65 Correct 8 ms 8132 KB Output is correct
66 Correct 8 ms 8012 KB Output is correct
67 Correct 7 ms 8140 KB Output is correct
68 Correct 8 ms 8012 KB Output is correct
69 Correct 8 ms 8012 KB Output is correct
70 Correct 8 ms 8164 KB Output is correct
71 Correct 8 ms 7884 KB Output is correct
72 Correct 8 ms 7948 KB Output is correct
73 Correct 7 ms 8140 KB Output is correct
74 Correct 7 ms 7756 KB Output is correct
75 Correct 7 ms 7892 KB Output is correct
76 Correct 10 ms 7956 KB Output is correct
77 Correct 8 ms 8124 KB Output is correct
78 Correct 8 ms 7844 KB Output is correct
79 Correct 7 ms 7912 KB Output is correct
80 Correct 7 ms 7884 KB Output is correct
81 Correct 7 ms 8012 KB Output is correct
82 Correct 7 ms 8044 KB Output is correct
83 Correct 8 ms 8084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7500 KB Output is correct
2 Correct 4 ms 7500 KB Output is correct
3 Correct 4 ms 7500 KB Output is correct
4 Correct 4 ms 7500 KB Output is correct
5 Correct 4 ms 7500 KB Output is correct
6 Correct 4 ms 7500 KB Output is correct
7 Correct 5 ms 7500 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7500 KB Output is correct
10 Correct 5 ms 7500 KB Output is correct
11 Correct 6 ms 7500 KB Output is correct
12 Correct 4 ms 7512 KB Output is correct
13 Correct 4 ms 7500 KB Output is correct
14 Correct 4 ms 7500 KB Output is correct
15 Correct 5 ms 7408 KB Output is correct
16 Correct 4 ms 7500 KB Output is correct
17 Correct 4 ms 7500 KB Output is correct
18 Correct 5 ms 7500 KB Output is correct
19 Correct 5 ms 7500 KB Output is correct
20 Correct 4 ms 7500 KB Output is correct
21 Correct 4 ms 7500 KB Output is correct
22 Correct 4 ms 7500 KB Output is correct
23 Correct 4 ms 7500 KB Output is correct
24 Correct 4 ms 7500 KB Output is correct
25 Correct 4 ms 7500 KB Output is correct
26 Correct 5 ms 7500 KB Output is correct
27 Correct 4 ms 7500 KB Output is correct
28 Correct 4 ms 7500 KB Output is correct
29 Correct 5 ms 7440 KB Output is correct
30 Correct 6 ms 7500 KB Output is correct
31 Correct 5 ms 7500 KB Output is correct
32 Correct 5 ms 7500 KB Output is correct
33 Correct 4 ms 7500 KB Output is correct
34 Correct 4 ms 7500 KB Output is correct
35 Correct 4 ms 7500 KB Output is correct
36 Correct 4 ms 7500 KB Output is correct
37 Correct 4 ms 7500 KB Output is correct
38 Correct 4 ms 7500 KB Output is correct
39 Correct 4 ms 7500 KB Output is correct
40 Correct 4 ms 7372 KB Output is correct
41 Correct 6 ms 7500 KB Output is correct
42 Correct 4 ms 7432 KB Output is correct
43 Correct 4 ms 7500 KB Output is correct
44 Correct 5 ms 7500 KB Output is correct
45 Correct 4 ms 7500 KB Output is correct
46 Correct 4 ms 7500 KB Output is correct
47 Correct 4 ms 7500 KB Output is correct
48 Correct 4 ms 7500 KB Output is correct
49 Correct 4 ms 7372 KB Output is correct
50 Correct 4 ms 7500 KB Output is correct
51 Correct 5 ms 7500 KB Output is correct
52 Correct 4 ms 7500 KB Output is correct
53 Correct 11 ms 8728 KB Output is correct
54 Correct 113 ms 20676 KB Output is correct
55 Correct 119 ms 20736 KB Output is correct
56 Correct 121 ms 20584 KB Output is correct
57 Correct 149 ms 20672 KB Output is correct
58 Correct 158 ms 26064 KB Output is correct
59 Correct 131 ms 23968 KB Output is correct
60 Correct 129 ms 24044 KB Output is correct
61 Correct 96 ms 21608 KB Output is correct
62 Correct 98 ms 21048 KB Output is correct
63 Correct 134 ms 20548 KB Output is correct
64 Correct 133 ms 20456 KB Output is correct
65 Correct 109 ms 23484 KB Output is correct
66 Correct 155 ms 27144 KB Output is correct
67 Correct 132 ms 27684 KB Output is correct
68 Correct 121 ms 20420 KB Output is correct
69 Correct 184 ms 20540 KB Output is correct
70 Correct 142 ms 20644 KB Output is correct
71 Correct 94 ms 21304 KB Output is correct
72 Correct 91 ms 21364 KB Output is correct
73 Correct 92 ms 21224 KB Output is correct
74 Correct 8 ms 8012 KB Output is correct
75 Correct 8 ms 8012 KB Output is correct
76 Correct 8 ms 8012 KB Output is correct
77 Correct 8 ms 8140 KB Output is correct
78 Correct 8 ms 8140 KB Output is correct
79 Correct 8 ms 8140 KB Output is correct
80 Correct 7 ms 8140 KB Output is correct
81 Correct 8 ms 8140 KB Output is correct
82 Correct 8 ms 8140 KB Output is correct
83 Correct 8 ms 8012 KB Output is correct
84 Correct 8 ms 7844 KB Output is correct
85 Correct 7 ms 8140 KB Output is correct
86 Correct 7 ms 8140 KB Output is correct
87 Correct 8 ms 8132 KB Output is correct
88 Correct 8 ms 8012 KB Output is correct
89 Correct 7 ms 8140 KB Output is correct
90 Correct 8 ms 8012 KB Output is correct
91 Correct 8 ms 8012 KB Output is correct
92 Correct 8 ms 8164 KB Output is correct
93 Correct 8 ms 7884 KB Output is correct
94 Correct 8 ms 7948 KB Output is correct
95 Correct 7 ms 8140 KB Output is correct
96 Correct 7 ms 7756 KB Output is correct
97 Correct 7 ms 7892 KB Output is correct
98 Correct 10 ms 7956 KB Output is correct
99 Correct 8 ms 8124 KB Output is correct
100 Correct 8 ms 7844 KB Output is correct
101 Correct 7 ms 7912 KB Output is correct
102 Correct 7 ms 7884 KB Output is correct
103 Correct 7 ms 8012 KB Output is correct
104 Correct 7 ms 8044 KB Output is correct
105 Correct 8 ms 8084 KB Output is correct
106 Correct 134 ms 19972 KB Output is correct
107 Correct 138 ms 19496 KB Output is correct
108 Correct 121 ms 19148 KB Output is correct
109 Correct 128 ms 18948 KB Output is correct
110 Correct 95 ms 21320 KB Output is correct
111 Correct 116 ms 21292 KB Output is correct
112 Correct 131 ms 19988 KB Output is correct
113 Correct 116 ms 16792 KB Output is correct
114 Correct 127 ms 18276 KB Output is correct
115 Correct 84 ms 21176 KB Output is correct
116 Correct 115 ms 20904 KB Output is correct
117 Correct 135 ms 20360 KB Output is correct
118 Correct 95 ms 21148 KB Output is correct
119 Correct 103 ms 16836 KB Output is correct
120 Correct 127 ms 16424 KB Output is correct
121 Correct 117 ms 16228 KB Output is correct
122 Correct 118 ms 16044 KB Output is correct
123 Correct 103 ms 21428 KB Output is correct
124 Correct 98 ms 21384 KB Output is correct
125 Correct 103 ms 21276 KB Output is correct
126 Correct 117 ms 20036 KB Output is correct
127 Correct 124 ms 19436 KB Output is correct
128 Correct 128 ms 19148 KB Output is correct
129 Correct 129 ms 18876 KB Output is correct
130 Correct 101 ms 21372 KB Output is correct
131 Correct 116 ms 21444 KB Output is correct
132 Correct 120 ms 19856 KB Output is correct
133 Correct 109 ms 16692 KB Output is correct
134 Correct 156 ms 18244 KB Output is correct
135 Correct 92 ms 21104 KB Output is correct
136 Correct 126 ms 19804 KB Output is correct
137 Correct 132 ms 20124 KB Output is correct
138 Correct 95 ms 21236 KB Output is correct
139 Correct 113 ms 16940 KB Output is correct
140 Correct 115 ms 16452 KB Output is correct
141 Correct 126 ms 16280 KB Output is correct
142 Correct 111 ms 16044 KB Output is correct
143 Correct 102 ms 21444 KB Output is correct
144 Correct 100 ms 21504 KB Output is correct
145 Correct 115 ms 21284 KB Output is correct
146 Correct 109 ms 14156 KB Output is correct
147 Correct 110 ms 13368 KB Output is correct
148 Correct 109 ms 13404 KB Output is correct
149 Correct 114 ms 14336 KB Output is correct
150 Correct 119 ms 21124 KB Output is correct
151 Correct 104 ms 14188 KB Output is correct
152 Correct 113 ms 15292 KB Output is correct
153 Correct 130 ms 15352 KB Output is correct
154 Correct 95 ms 16832 KB Output is correct
155 Correct 104 ms 21088 KB Output is correct
156 Correct 124 ms 16944 KB Output is correct
157 Correct 92 ms 16436 KB Output is correct
158 Correct 94 ms 16152 KB Output is correct
159 Correct 130 ms 20224 KB Output is correct
160 Correct 134 ms 24636 KB Output is correct
161 Correct 169 ms 19696 KB Output is correct
162 Correct 97 ms 20736 KB Output is correct