<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>wuyihe</title><description>Notes</description><link>https://fuwari.vercel.app/</link><language>zh_CN</language><item><title>索引</title><link>https://fuwari.vercel.app/posts/%E7%B4%A2%E5%BC%95/</link><guid isPermaLink="true">https://fuwari.vercel.app/posts/%E7%B4%A2%E5%BC%95/</guid><pubDate>Mon, 05 Oct 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;你好&lt;/p&gt;
</content:encoded></item><item><title>ABC459 A-E题解</title><link>https://fuwari.vercel.app/posts/abc/</link><guid isPermaLink="true">https://fuwari.vercel.app/posts/abc/</guid><pubDate>Mon, 05 Oct 2026 00:00:00 GMT</pubDate><content:encoded>&lt;h1&gt;[A - Hell, World!](&lt;a href=&quot;https://atcoder.jp/contests/abc459/tasks/abc459_a&quot;&gt;A - Hell, World!&lt;/a&gt;)&lt;/h1&gt;
&lt;h6&gt;难度：入门；标签：&lt;a href=&quot;https://oi-wiki.net/string/basic/&quot;&gt;字符串&lt;/a&gt;&lt;/h6&gt;
&lt;h2&gt;题目大意&lt;/h2&gt;
&lt;p&gt;在字符串&lt;code&gt;HelloWold&lt;/code&gt;中，删除第 $X$ 个字符并输出。&lt;/p&gt;
&lt;h2&gt;具体思路&lt;/h2&gt;
&lt;p&gt;很明显，由于C++的字符串是下标是由零开始的，所以只需要&lt;a href=&quot;https://oi-wiki.net/lang/loop/&quot;&gt;循坏&lt;/a&gt;&lt;a href=&quot;https://oi-wiki.net/lang/branch/&quot;&gt;判断&lt;/a&gt;
下标是不是 $X - 1$ 就行了。&lt;/p&gt;
&lt;h2&gt;代码实现&lt;/h2&gt;
&lt;h6&gt;&lt;a href=&quot;https://oi-wiki.net/basic/complexity/&quot;&gt;时间复杂度&lt;/a&gt;：$O(N)$；&lt;a href=&quot;https://oi-wiki.net/basic/complexity/#%E7%A9%BA%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6&quot;&gt;空间复杂度&lt;/a&gt;：$O(N)$&lt;/h6&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
#define ll long long
#define cll const long long
#define ull unsigned long long
#define db double
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define pb push_back
#define pp pop_back()
#define pr pair&amp;lt;ll, ll&amp;gt;
#define fir first
#define sec second
cll N = 1e5 + 10;
ll x;
void solve(){
	string s = &quot;HelloWorld&quot;;
	cin &amp;gt;&amp;gt; x;
	for(ll i = 0;i &amp;lt; 10;i++)
		if(i != x - 1)
			cout &amp;lt;&amp;lt; s[i];
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	ll T = 1;
	// cin &amp;gt;&amp;gt; T;
	while(T--)
		solve();
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h1&gt;[B - 459](&lt;a href=&quot;https://atcoder.jp/contests/abc459/tasks/abc459_b&quot;&gt;B - 459&lt;/a&gt;)&lt;/h1&gt;
&lt;h6&gt;难度：入门；标签：字符串、&lt;a href=&quot;https://oi-wiki.net/basic/simulate/&quot;&gt;模拟&lt;/a&gt;&lt;/h6&gt;
&lt;h2&gt;题目大意&lt;/h2&gt;
&lt;p&gt;有 $N$ 个字符串（后文称 $S_i(1\le i \le N)$），取 $S_i$ 的首字母，把他转变成 $C_i$。
根据以下信息转变：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;若 $S_i$ 的首字符为 a, b, c 之一，则 $C_i = 2$。&lt;/li&gt;
&lt;li&gt;若 $S_i$ 的首字符为 d, e, f 之一，则 $C_i = 3$。&lt;/li&gt;
&lt;li&gt;若 $S_i$ 的首字符为 g, h, i 之一，则 $C_i = 4$。&lt;/li&gt;
&lt;li&gt;若 $S_i$ 的首字符为 j, k, l 之一，则 $C_i = 5$。&lt;/li&gt;
&lt;li&gt;若 $S_i$ 的首字符为 m, n, o 之一，则 $C_i = 6$。&lt;/li&gt;
&lt;li&gt;若 $S_i$ 的首字符为 p, q, r, s 之一，则 $C_i = 7$。&lt;/li&gt;
&lt;li&gt;若 $S_i$ 的首字符为 t, u, v 之一，则 $C_i = 8$。&lt;/li&gt;
&lt;li&gt;若 $S_i$ 的首字符为 w, x, y, z 之一，则 $C_i = 9$。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;最后连接 $C_1,C_2,C_3,...,C_n$，输出即可。&lt;/p&gt;
&lt;h2&gt;具体思路&lt;/h2&gt;
&lt;p&gt;这道题也很简单，只需循坏遍历每一个字符串，取首字母判断输出就行了&lt;/p&gt;
&lt;h2&gt;代码实现&lt;/h2&gt;
&lt;h6&gt;时间复杂度$O(N)$；空间复杂度：$O(N)$&lt;/h6&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
#define ll long long
#define cll const long long
#define ull unsigned long long
#define db double
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define pb push_back
#define pp pop_back()
#define pr pair&amp;lt;ll, ll&amp;gt;
#define fir first
#define sec second
cll N = 1e5 + 10;
ll n;
void solve(){
	cin &amp;gt;&amp;gt; n;
	for(ll i = 1;i &amp;lt;= n;i++){
		string s;
		cin &amp;gt;&amp;gt; s;
		s = &quot;0&quot; + s;
		if(s[1] == &apos;a&apos; || s[1] == &apos;b&apos; || s[1] == &apos;c&apos;)
			cout &amp;lt;&amp;lt; 2;
		else if(s[1] == &apos;d&apos; || s[1] == &apos;e&apos; || s[1] == &apos;f&apos;)
			cout &amp;lt;&amp;lt; 3;
		else if(s[1] == &apos;g&apos; || s[1] == &apos;h&apos; || s[1] == &apos;i&apos;)
			cout &amp;lt;&amp;lt; 4;
		else if(s[1] == &apos;j&apos; || s[1] == &apos;k&apos; || s[1] == &apos;l&apos;)
			cout &amp;lt;&amp;lt; 5;
		else if(s[1] == &apos;m&apos; || s[1] == &apos;n&apos; || s[1] == &apos;o&apos;)
			cout &amp;lt;&amp;lt; 6;
		else if(s[1] == &apos;p&apos; || s[1] == &apos;q&apos; || s[1] == &apos;r&apos; || s[1] == &apos;s&apos;)
			cout &amp;lt;&amp;lt; 7;
		else if(s[1] == &apos;t&apos; || s[1] == &apos;u&apos; || s[1] == &apos;v&apos;)
			cout &amp;lt;&amp;lt; 8;
		else
			cout &amp;lt;&amp;lt; 9;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	ll T = 1;
	// cin &amp;gt;&amp;gt; T;
	while(T--)
		solve();
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h1&gt;[C - Drop Blocks](&lt;a href=&quot;https://atcoder.jp/contests/abc459/tasks/abc459_c&quot;&gt;C - Drop Blocks&lt;/a&gt;)&lt;/h1&gt;
&lt;h6&gt;难度：普及/提高-；标签：模拟&lt;/h6&gt;
&lt;h2&gt;题目大意&lt;/h2&gt;
&lt;p&gt;给你 $N$ 个单元格，最开始每个单元格都没有积木。
一共有两种操作：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;1 x&lt;/code&gt;：将一个图块放入第 $X$ 个单元格中。如果每个单元格都有1个积木，则让所有单元格的数量减一。&lt;/li&gt;
&lt;li&gt;&lt;code&gt;2 y&lt;/code&gt;：查询所有单元格中积木数大于 $Y$ 个的单元格数量并输出。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;具体思路&lt;/h2&gt;
&lt;p&gt;这道题如果用&lt;a href=&quot;https://oi-wiki.net/lang/array/&quot;&gt;数组&lt;/a&gt;去存每一个单元格中积木数量，那么时间复杂度为 $O(QN)$ （因为每个操作都需要 O（N）去做）。
由于 $1 \le N,Q \le 3 \times 10^5$，肯定会超时，所以我们引入一个新的&lt;a href=&quot;https://blog.csdn.net/2401_87910242/article/details/161314673?ops_request_misc=&amp;amp;request_id=&amp;amp;biz_id=102&amp;amp;utm_term=STL%E6%98%AF%E4%BB%80%E4%B9%88&amp;amp;utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-161314673.142%5Ev102%5Epc_search_result_base3&amp;amp;spm=1018.2226.3001.4187&quot;&gt;STL&lt;/a&gt;容器&lt;a href=&quot;https://oi-wiki.net/ds/hash/&quot;&gt;哈希表&lt;/a&gt;，这里我用的是&lt;code&gt;unordered_map&lt;/code&gt;，不知道的&lt;a href=&quot;https://blog.csdn.net/weixin_45031801/article/details/142033774?ops_request_misc=elastic_search_misc&amp;amp;request_id=e69550b9517c5763678a012095b45386&amp;amp;biz_id=0&amp;amp;utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-142033774-null-null.142%5Ev102%5Epc_search_result_base3&amp;amp;utm_term=unordered_map&amp;amp;spm=1018.2226.3001.4187&quot;&gt;看这里&lt;/a&gt;。
这里我为了更快处理操作1，引入了懒标记（就是先不做操作，等要用的时候再更新）。&lt;/p&gt;
&lt;h2&gt;代码实现&lt;/h2&gt;
&lt;h6&gt;时间复杂度：$\approx O(Q)$；空间复杂度：$O(N)$&lt;/h6&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
#define ll long long
#define cll const long long
#define ull unsigned long long
#define db double
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define pb push_back
#define pp pop_back()
#define pr pair&amp;lt;ll, ll&amp;gt;
#define fir first
#define sec second
cll N = 3e5 + 10;
ll n, q, cha, a[N];
unordered_map&amp;lt;ll, ll&amp;gt;sum;
void solve(){
	cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; q;
	sum[0] = n;
	while(q--){
		ll op;
		cin &amp;gt;&amp;gt; op;
		if(op == 1){
			ll x;
			cin &amp;gt;&amp;gt; x;
			sum[a[x]]--;
			if(!sum[a[x]])
				sum.erase(a[x]);
			a[x]++;
			sum[a[x]]++;
			if(!sum.count(cha))
				cha++;
		}else{
			ll y;
			cin &amp;gt;&amp;gt; y;
			ll ans = 0;
			for(auto &amp;amp;[num, cnt] : sum)
				if(num - cha &amp;gt;= y)
					ans += cnt;
			cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &quot;\n&quot;;
		}
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	ll T = 1;
	// cin &amp;gt;&amp;gt; T;
	while(T--)
		solve();
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;这时候有人就要问了，为什么操作2没超时呢。
我们来进行《一点点》&lt;strong&gt;数学&lt;/strong&gt;推导。
首先由于 $1 \le Q \le 3 \times 10^5$。
我要们最大限度利用数字，所以公式为 $0 + 1 + 2 + 3 + 4 +...+X = Q = \frac {X(X+1)}{2}$
如果 $Q = 3 \times 10^5$。
则列出&lt;a href=&quot;https://blog.csdn.net/xuchaoxin1375/article/details/144832962?ops_request_misc=elastic_search_misc&amp;amp;request_id=2d43b4e62884e689a3ce422231e1c67a&amp;amp;biz_id=0&amp;amp;utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-2-144832962-null-null.142%5Ev102%5Epc_search_result_base3&amp;amp;utm_term=%E4%B8%80%E5%85%83%E4%BA%8C%E6%AC%A1%E6%96%B9%E7%A8%8B&amp;amp;spm=1018.2226.3001.4187&quot;&gt;一元二次方程&lt;/a&gt;：
$X^2 + X - 6 \times 10^5 = 0$
$\Delta = b^2 - 4ac = 1^2 + 2.4 \times 10^6 &amp;gt; 0$
所有该方程有解并有两个根，根据求根公式，得：
$\frac{-b \pm \sqrt{\Delta}}{2a} = \frac{-1 \pm \sqrt{2400001}}{2}$
则
$x_1 \approx 764,x_2 \approx -775$
由于积木数大于等于0，则保留 $x_1$，所以哈希表内最多有765个数字。
则操作2需要的时间复杂度为 $O(765)(因为前面操作1用掉了操作数)$
所以不用担心超时。&lt;/p&gt;
&lt;h1&gt;[D - Adjacent Distinct String](&lt;a href=&quot;https://atcoder.jp/contests/abc459/tasks/abc459_d&quot;&gt;D - Adjacent Distinct String&lt;/a&gt;)&lt;/h1&gt;
&lt;h6&gt;难度：普及/提高-；标签：字符串、&lt;a href=&quot;https://oi-wiki.net/basic/greedy/&quot;&gt;贪心&lt;/a&gt;&lt;/h6&gt;
&lt;h2&gt;题目大意&lt;/h2&gt;
&lt;p&gt;给你一个字符串，在字符串的&lt;a href=&quot;https://blog.csdn.net/qq_40454136/article/details/132079655?ops_request_misc=&amp;amp;request_id=&amp;amp;biz_id=102&amp;amp;utm_term=%E5%85%A8%E6%8E%92%E5%88%97&amp;amp;utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-132079655.142%5Ev102%5Epc_search_result_base3&amp;amp;spm=1018.2226.3001.4449&quot;&gt;全排列&lt;/a&gt;里找出&lt;strong&gt;一种&lt;/strong&gt;方法使得 $S_i \ne S_{i + 1}(1 \le i &amp;lt; N)$。&lt;/p&gt;
&lt;h2&gt;具体思路&lt;/h2&gt;
&lt;p&gt;首先我们可以想到一种构造方式为&lt;code&gt;xyxy...xyx&lt;/code&gt;，也就是我们拿最多的和第二多的进行排列。如果除了最多的字符没有其他字符了，那就证明不合法。我们可以用priority_queue（&lt;a href=&quot;https://oi-wiki.net/lang/csl/container-adapter/#%E4%BC%98%E5%85%88%E9%98%9F%E5%88%97&quot;&gt;优先队列&lt;/a&gt;）来实时更新。&lt;/p&gt;
&lt;h2&gt;代码实现&lt;/h2&gt;
&lt;h6&gt;时间复杂度：$\approx O(N)$；空间复杂度：$O(N)$&lt;/h6&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
#define ll long long
#define cll const long long
#define ull unsigned long long
#define db double
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define pb push_back
#define pp pop_back()
#define pr pair&amp;lt;ll, ll&amp;gt;
#define fir first
#define sec second
cll N = 3e5 + 10;
string s;
void solve(){
	cin &amp;gt;&amp;gt; s;
	string ans;
	ll sum[30];
	memset(sum, 0, sizeof sum);
	for(char &amp;amp;e : s)
		sum[e - &apos;a&apos;]++;
	priority_queue&amp;lt;pr&amp;gt;q;
	for(ll i = 0;i &amp;lt; 26;i++)
		if(sum[i] != 0)
			q.push({sum[i], i});
	while(q.size()){
		auto [num1, c1] = q.top();
		q.pop();
		if(num1 == 1 || ans.back() == char(c1 + &apos;a&apos;)){
			ans.pb(char(c1 + &apos;a&apos;));
			continue;
		}
		if(!q.size()){
			cout &amp;lt;&amp;lt; &quot;No\n&quot;;
			return;
		}
		auto [num2, c2] = q.top();
		q.pop();
		ans.pb(char(c1 + &apos;a&apos;));
		ans.pb(char(c2 + &apos;a&apos;));
		q.push({num1 - 1, c1});
		if(num2 &amp;gt; 1)
			q.push({num2 - 1, c2});
	}
	cout &amp;lt;&amp;lt; &quot;Yes\n&quot;;
	cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &quot;\n&quot;;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	ll T = 1;
	cin &amp;gt;&amp;gt; T;
	while(T--)
		solve();
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h1&gt;[E - Select from Subtrees](&lt;a href=&quot;https://atcoder.jp/contests/abc459/tasks/abc459_e&quot;&gt;E - Select from Subtrees&lt;/a&gt;)&lt;/h1&gt;
&lt;h6&gt;难度：普及+/提高；标签：&lt;a href=&quot;https://oi-wiki.net/dp/tree/&quot;&gt;树形DP&lt;/a&gt;、&lt;a href=&quot;https://oi-wiki.net/graph/topo/&quot;&gt;拓扑排序&lt;/a&gt;、&lt;a href=&quot;https://oi-wiki.net/math/combinatorics/combination/&quot;&gt;组合数学&lt;/a&gt;&lt;/h6&gt;
&lt;h2&gt;题目大意&lt;/h2&gt;
&lt;p&gt;给你一颗根为1的&lt;a href=&quot;https://oi-wiki.net/graph/tree-basic/&quot;&gt;树&lt;/a&gt;，第 $i$ 个节点的父亲是 $P_i$，第 $i$ 个节点上有 $C_i$ 个糖果，第 $i$只松鼠要拿 $D_i$ 颗糖果，松鼠取的糖果要从是他的子树拿，且第 $i$ 只松鼠在第 $i$ 个节点上，问你松鼠选择糖果的方案数对 $998244353$ 取模是多少。&lt;/p&gt;
&lt;h2&gt;具体思路&lt;/h2&gt;
&lt;p&gt;根据题面我们就知道第 $i$ 松鼠要从 $X$ 颗糖果中取 $D_i$ 颗，很明显这就是组合数学中的组合数，公式为：$C_n^k = \frac{n!}{k!(n - k)!}$。&lt;/p&gt;
&lt;p&gt;由于题目中要取模，且998244353为质数，则可以使用&lt;a href=&quot;https://oi-wiki.net/math/number-theory/inverse/&quot;&gt;逆元&lt;/a&gt;的知识，公式为 $\frac{a}{b} \equiv a \times b^{p-2} (\mod p)$，则公式可化简为：$\frac{n!}{k!(n - k)!} \equiv n! \times (k!(n-k)!)^{p-2}(\mod p)$。&lt;/p&gt;
&lt;p&gt;我们可以设 $fact_i$ 为 $i!$，$inv_i$ 为 $(i!)^{-1}$(逆元)。很明显根据 $n! = n \times (n - 1)!$，$fact_i = i * fact_{i-1}$。&lt;/p&gt;
&lt;p&gt;那 $inv_i$ 怎么求呢？我们可以根据逆元的性质 $a \equiv b \times c (\mod p)$ 则 $a^{-1} \equiv b^{-1} \times c^{-1}(\mod p)$，得 $(n!)^{-1} \equiv n^{-1} \times [(n-1)!]^{-1}(\mod p)$。我们用 $inv$ 数组表示，就是 $inv_i \equiv i^{-1} \times inv_{i - 1}$。再根据逆元的性质：$n \times n^{-1} \equiv 1(\mod p)$，我们在两边同时乘上 $i$，得 $inv_i \times i \equiv i^{-1} \times i \times inv_{i-1}(\mod p)$。也就是 $inv_{i-1} \equiv inv_i \times i(\mod p)$ 。&lt;/p&gt;
&lt;p&gt;然后我们该如何遍历呢？由于我的注意力惊人，发现在叶子节点的松鼠，根本不受干扰，然后他的父亲就等于他的孩子剩余糖果和加上自己的所在节点的糖果，进行组合数计算就行了。这很像拓扑排序的思想。&lt;/p&gt;
&lt;p&gt;然后这道题就写完了&lt;/p&gt;
&lt;h2&gt;代码实现&lt;/h2&gt;
&lt;h6&gt;时间复杂度：$O(N)$；空间复杂度：$O(N)$&lt;/h6&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
#define ll long long
#define cll const long long
#define ull unsigned long long
#define db double
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define pb push_back
#define pp pop_back()
#define pr pair&amp;lt;ll, ll&amp;gt;
#define fir first
#define sec second
cll N = 3e6 + 10, M = 2e5 + 10, mod = 998244353;
ll n, p[M], deg[M], c[M], d[M], ans = 1, num[M], deg2[M];
vector&amp;lt;ll&amp;gt; fact(N), inv(N); 
ll qpow(ll a, ll b) { 
	ll res = 1; 
	while (b &amp;gt; 0) {
		if (b % 2 == 1) 
			res = res * a % mod;
		a = a * a % mod; 
		b &amp;gt;&amp;gt;= 1; 
	} 
	return res;
}
void init() { 
	fact[0] = 1; 
	for (ll i = 1; i &amp;lt; N; i++) 
		fact[i] = fact[i - 1] * i % mod; 
	inv[N-1] = qpow(fact[N - 1], mod - 2); 
	for (ll i = N-2; i &amp;gt;= 0; i--) 
		inv[i] = inv[i + 1] * (i + 1) % mod; 
} 
ll C(ll n, ll k){
    if (k &amp;lt; 0 || k &amp;gt; n) return 0;
    ll res = 1;
    for (ll i = 0; i &amp;lt; k; i++)
        res = res * ((n - i) % mod) % mod;
    return res * inv[k] % mod;
}
void solve(){
	cin &amp;gt;&amp;gt; n;
	for(ll i = 2;i &amp;lt;= n;i++){
		cin &amp;gt;&amp;gt; p[i];
		deg[p[i]]++;
	}
	for(ll i = 1;i &amp;lt;= n;i++)
		cin &amp;gt;&amp;gt; c[i], num[i] = c[i];
	for(ll i = 1;i &amp;lt;= n;i++)
		cin &amp;gt;&amp;gt; d[i];
	queue&amp;lt;ll&amp;gt;q;
	for(ll i = 1;i &amp;lt;= n;i++){
		if(deg[i] == 0)
			q.push(i);
	}
	while(q.size()){
		ll u = q.front();
		q.pop();
        if(C(num[u], d[u]) == 0){
            cout &amp;lt;&amp;lt; 0;
            return;
        }
		ans = ans % mod * C(num[u], d[u]);
        if(u == 1)
            continue;
		num[p[u]] += (num[u] - d[u]);
		deg[p[u]]--;
		if(deg[p[u]] == 0)
			q.push(p[u]);
	}
	cout &amp;lt;&amp;lt; ans % mod &amp;lt;&amp;lt; &quot;\n&quot;;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	init();
	ll T = 1;
	// cin &amp;gt;&amp;gt; T;
	while(T--)
		solve();
	return 0;
}
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item></channel></rss>