当前位置:网站首页>P6154 wandering (memory search
P6154 wandering (memory search
2022-06-13 07:18:00 【lcxdz】
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+9, mod=998244353;
int tot[N],sum[N];
vector<int>v[N];
int dfs(int u){
if(tot[u])return tot[u];
tot[u]=1;
for(auto it:v[u]){
int p=dfs(it);
tot[u]+=p;// Number of nodes after adding
sum[u]+=p+sum[it];// Add the number of subsequent nodes and the distance from the current node to the subsequent nodes
tot[u]%=mod;
sum[u]%=mod;
}
return tot[u];
}
int q_pow(int a,int b){
int ans=1;
while(b){
if(b&1)ans=ans*a%mod;
b>>=1;
a=a*a%mod;
}
return ans;
}
signed main(){
int n,m;
cin>>n>>m;
while(m--){
int x,y;
cin>>x>>y;
v[x].push_back(y);
}
for(int i=1;i<=n;i++){
dfs(i);
}
int a=0,b=0;
for(int i=1;i<=n;i++){
a+=sum[i];
b+=tot[i];
a%=mod;
b%=mod;
}
// cout<<a<<" "<<b<<"\n";
cout<<a*q_pow(b,mod-2)%mod;
return 0;
}
边栏推荐
- redis-6. Redis master-slave replication, cap, Paxos, cluster sharding cluster 01
- Raspberry school advanced development - "writing of IO port driver code" includes bus address, physical \u virtual address and bcm2835 chip manual knowledge
- RT thread simulator lvgl control: switch switch button control
- Detailed description of drawing ridge plot, overlapping densities of overlapping kernel density estimation curve, facetgrid object and function sns Kdeplot, function facetgrid map
- Interview questions must be asked - Optimization of large table Pagination
- Through the function seaborn cubehelix_ Palette build order palette
- 10 Honest Facts I Want To Share With All Junior Developers
- It's called the next generation monitoring system. Let's see how awesome it is
- WWDC2022最大的亮点: MetalFX
- 基于FPGA的ds18b20温度传感器使用
猜你喜欢

Un des backtraders du cadre de quantification lit l'analyseur

【ViveFocus使用WaveVR插件获取手柄操作事件】

JMeter encryption interface test

10 Honest Facts I Want To Share With All Junior Developers

RT thread simulator lvgl control: button button event

量化框架backtrader之一文读懂Analyzer分析器

RT-Thread 模拟器 simulator LVGL控件:button 按钮样式

redis-5. Redis' RDB, fork, copyonwrite, AOF, RDB & AOF are mixed

Test development programmers, are you still confused? You can't define yourself as a yard farmer

The biggest highlight of wwdc2022: metalfx
随机推荐
Make cer/pfx public and private key certificates and export CFCA application certificates
redis-4. Redis' message subscription, pipeline, transaction, modules, bloom filter, and cache LRU
FTP_ Manipulate remote files
玄武云科技通过上市聆讯:业绩波动明显,陈永辉等三人为控股股东
对绘制丘岭密度图ridge plot的详细说明、重叠核密度估计曲线overlapping densities、FacetGrid对象、函数sns.kdeplot、函数FacetGrid.map
【RS-422与RS-485】RS-422与RS-485串行接口标准
Number of detection cycles "142857“
redis-1. Install redis with pictures and texts
不间断管理设计
FSM state machine
TXT_ File encryption and compression
redis-0. Introduction to redis and NiO principle (random talk)
Ticdc synchronization task
How worker threads in the thread pool are recycled
QT读取SQLserver数据库
How is it that the income of financial products is zero for several consecutive days?
Implementation of fruit mall wholesale platform based on SSM
C#合并多个richtextbox内容时始终存在换行符的解决方法
2022-06-12:在N*N的正方形棋盘中,有N*N个棋子,那么每个格子正好可以拥有一个棋子。 但是现在有些棋子聚集到一个格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二维数组代表,一
通过函数seaborn.cubehelix_palette生成顺序调色板