当前位置:网站首页>AcWing 1134. Shortest circuit counting problem solution (shortest circuit)
AcWing 1134. Shortest circuit counting problem solution (shortest circuit)
2022-07-02 19:32:00 【Mr. Qiao Da】
AcWing 1134. Shortest circuit count
Path weights are 1, use bfs Find the shortest path , In the process of finding cnt The array records the number of routes , Note that when the path lengths are equal , You need to add and update the number of the two paths
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, M = 4 * N, INF = 0x3f3f3f3f;
int h[N], e[M], ne[M], idx;
int n, m;
int dist[N];
int cnt[N];
int q[N];
int w[N];
void Add(int a, int b){
e[idx] = b;
ne[idx] = h[a];
h[a] = idx ++ ;
}
void bfs(){
memset(dist, 0x3f, sizeof dist);
int hh = 0, tt = 0;
q[0] = 1;
dist[1] = 0;
cnt[1] = 1;
while(hh <= tt){
int t = q[hh ++ ];
for(int i = h[t]; ~i; i = ne[i]){
int j = e[i];
if(dist[j] > dist[t] + 1){
dist[j] = dist[t] + 1;
cnt[j] = cnt[t];
q[ ++ tt] = j;
}
else if(dist[j] == dist[t] + 1){
cnt[j] = (cnt[j] + cnt[t]) % 100003;
}
}
}
}
int main()
{
cin>>n>>m;
memset(h, -1, sizeof h);
while(m -- ){
int a, b;
cin>>a>>b;
Add(a, b);
Add(b, a);
}
bfs();
for(int i = 1; i <= n; i ++ ){
cout<<cnt[i]<<endl;
}
return 0;
}
边栏推荐
- juypter notebook 修改默认打开文件夹以及默认浏览器
- 《架构整洁之道》读书笔记(下)
- Codeworks 5 questions per day (1700 average) - day 4
- AcWing 340. 通信线路 题解(二分+双端队列BFS求最短路)
- Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
- 《重构:改善既有代码的设计》读书笔记(下)
- AcWing 1125. 牛的旅行 题解(最短路、直径)
- 中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
- Machine learning notes - time series prediction research: monthly sales of French champagne
- Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
猜你喜欢

According to the atlas of data security products and services issued by the China Academy of information technology, meichuang technology has achieved full coverage of four major sectors

教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 網絡安全專家 NSE 5

AcWing 1126. 最小花费 题解(最短路—dijkstra)

Compile oglpg-9th-edition source code with clion

教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5

codeforces每日5题(均1700)-第四天

End to end object detection with transformers (Detr) paper reading and understanding

AcWing 342. 道路与航线 题解 (最短路、拓扑排序)

线程应用实例

程序猿入门攻略(十二)——数据的存储
随机推荐
潇洒郎:彻底解决Markdown图片问题——无需上传图片——无需网络——转发给他人图片无缺失
PHP parser badminton reservation applet development requires online system
QT中的QPropertyAnimation使用和toast案列
函数高阶-柯里化实现
开发固定资产管理系统,开发固定资产管理系统用什么语音
Codeworks 5 questions per day (1700 average) - day 4
Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
Introduction of Ethernet PHY layer chip lan8720a
AcWing 340. 通信线路 题解(二分+双端队列BFS求最短路)
Gmapping code analysis [easy to understand]
Idea editor removes SQL statement background color SQL statement warning no data sources are configured to run this SQL And SQL dialect is not config
《代碼整潔之道》讀書筆記
mysql备份后缀是什么_mysql备份还原
Windows2008r2 installing php7.4.30 requires localsystem to start the application pool, otherwise 500 error fastcgi process exits unexpectedly
二进制操作
数字滚动带动画
C的内存管理
AcWing 1127. 香甜的黄油 题解(最短路—spfa)
Golang concurrent programming goroutine, channel, sync
Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出