当前位置:网站首页>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;
}
边栏推荐
- 程序猿入门攻略(十二)——数据的存储
- [pytorch learning notes] tensor
- Gamefi chain game system development (NFT chain game development function) NFT chain game system development (gamefi chain game development source code)
- 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
- 《重构:改善既有代码的设计》读书笔记(上)
- Horizontal ultra vires and vertical ultra vires [easy to understand]
- Yunna | why use the fixed asset management system and how to enable it
- Virtual machine initialization script, virtual machine mutual secret key free
- 搭建哨兵模式reids、redis从节点脱离哨兵集群
- Mobile robot path planning: artificial potential field method [easy to understand]
猜你喜欢
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达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
xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
juypter notebook 修改默认打开文件夹以及默认浏览器
Usage of ieda refactor
Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出
Watchful pioneer world outlook Architecture - (how does a good game come from)
云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统
潇洒郎:彻底解决Markdown图片问题——无需上传图片——无需网络——转发给他人图片无缺失
Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
随机推荐
Tutoriel (5.0) 10. Dépannage * fortiedr * fortinet Network Security expert NSE 5
Virtual machine initialization script, virtual machine mutual secret key free
开发固定资产管理系统,开发固定资产管理系统用什么语音
Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出
思考变量引起的巨大变化
Reading notes of code neatness
LeetCode 0871.最低加油次数 - 类似于POJ2431丛林探险
Markdown basic grammar
使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
Is there any security guarantee for the ranking of stock and securities companies
程序猿入门攻略(十二)——数据的存储
juypter notebook 修改默认打开文件夹以及默认浏览器
Golang并发编程——goroutine、channel、sync
冒泡排序数组
MySQL table historical data cleaning summary
Bubble sort array
Use cheat engine to modify money, life and stars in Kingdom rush
【ERP软件】ERP体系二次开发有哪些危险?
Advanced performance test series "24. Execute SQL script through JDBC"
Emmet基础语法