当前位置:网站首页>Luogu p1608 path statistics solution
Luogu p1608 path statistics solution
2022-06-21 22:08:00 【q779】
Luogu P1608 Path Statistics Answer key
Topic link :P1608 Path Statistics
The question :
One sentence question : Shortest circuit count .
“RP The restaurant ” The quality of the staff is not average , After calculating the same phone number in unison , Ready to let HZH,TZY To deliver fast food , They drew a map of the city where they lived , Known on their maps , Yes N N N A place to , And they are currently in a position marked “1” In a small town , The place of delivery is marked as “N” The town of .( It's a bit of rubbish ) Besides, I also know that these roads are one-way , From the town I I I To J J J Need to spend D [ I , J ] D[I, J] D[I,J] Time for , In order to deliver fast food to customers more efficiently and quickly , They want to take a route from the town 1 1 1 To the town N N N The least expensive way , But before they set out , Hit someone who was angry because of the traffic jam on the road FYY, Inspired by , You can't just know one route , In case ... therefore , They invited FYY Let's study the next question : How many paths are there that cost the least ?
about 100 % 100\% 100% The data of 1 ≤ N ≤ 2000 1\leq N\leq 2000 1≤N≤2000, 0 ≤ E ≤ N × ( N − 1 ) 0\leq E\leq N\times (N-1) 0≤E≤N×(N−1), 1 ≤ C ≤ 10 1\leq C\leq 10 1≤C≤10.
The data of the shortest path meter says that it cannot be used spfa(spfa Is dead )
set up f u f_u fu From the beginning to the beginning u u u The shortest path number of nodes
Obviously with dijkstra Brush Watch
if ( u , v ) (u,v) (u,v) Relaxation succeeded , That is to say
d[v]>d[u]+w
Let's just let f[v]=f[u]
Otherwise, if
d[v]==d[u]+w
let f[v]+=f[u]
be without , That's the water
Time complexity O ( n log m ) O(n \log m) O(nlogm) , Here I write the adjacency matrix so m ≈ n 2 m \approx n^2 m≈n2
Code :
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <queue>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define N (int)(2e3+15)
int n,m,d[N],vis[N],f[N],g[N][N];
struct node
{
int u,dis;
bool operator<(const node &o)const
{
return dis>o.dis;}
};
priority_queue<node> q;
void dijkstra(int st)
{
memset(d,0x3f,sizeof(d));
d[st]=0;f[st]=1;
q.push({
st,0});
while(!q.empty())
{
int u=q.top().u;q.pop();
if(vis[u])continue;
vis[u]=1;
for(int v=1,w; v<=n; v++)
{
if((w=g[u][v])>=INF)continue;
if(d[v]>d[u]+w)
{
d[v]=d[u]+w;
f[v]=f[u];
q.push({
v,d[v]});
}else if(d[v]==d[u]+w)f[v]+=f[u];
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("check.in","r",stdin);
// freopen("check.out","w",stdout);
cin >> n >> m;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
g[i][j]=INF;
for(int i=1,u,v,w; i<=m; i++)
{
cin >> u >> v >> w;
g[u][v]=min(g[u][v],w);
}
dijkstra(1);
if(d[n]>=INF)cout << "No answer\n";
else cout << d[n] << " " << f[n];
return 0;
}
Reprint please explain the source
边栏推荐
- 文件I/O
- How to use the free and easy-to-use reference management software Zotero? Can I support both Chinese and English
- 广东疾控提醒:暑期将至,返粤大学生这样安全“归巢”
- AWS CloudWatch
- 处理订单业务多面手,订货管理系统实现企业订货库存统一管理
- Introduction to security encryption
- I2C [2] - why does IIC need to use open drain output and pull-up resistor bug
- Implement a middleware from -1
- I2C [1] - I2C drive debug read operation abnormal bug
- Leetcode508- the most frequent subtree elements and - deep search
猜你喜欢
![P6758 [BalticOI2013] Vim](/img/07/b16c8d329b33424e931d9eaedae73a.png)
P6758 [BalticOI2013] Vim

搭建Eureka-Server集群

传承百年经典的瑞吉管家静待您的优雅旅程再次开启
![Jerry's problem of playing songs after opening four channel EQ [chapter]](/img/ef/16d630b44df9b1c700bf8cf6acf8b2.png)
Jerry's problem of playing songs after opening four channel EQ [chapter]

What are the authoritative websites that search English documents like CNKI?

华为鸿蒙开发第三课
Go language unit test basics from getting started to giving up

处理订单业务多面手,订货管理系统实现企业订货库存统一管理

B2B商城网站助力企业加快分销速度,构建高效智能的B2B网上分销平台

Using streamapi assertion combination and local cache for fuzzy query (nearly 1000 times more efficient than MySQL)
随机推荐
央企国电集团上海翔伟机电和中外海达成战略合作,捐赠2亿
电子招标采购商城系统:优化传统采购业务,提速企业数字化升级
InteliJ-IDEA-高效技巧(一)
Utilisation de la combinaison d'assertions de l'API Stream et de la mise en cache locale pour les requêtes floues (près de 1000 fois plus efficace que MySQL)
I2C【1】-I2C驱动调试读操作异常的bug
使用StreamAPI 斷言組合,結合本地緩存做模糊查詢(比mysql效率提昇近1000倍)
超越同龄人,普通女生下班后如何自学自媒体视频剪辑?
Prototype extension: implementing object inheritance
Introduction to security encryption
洛谷P1608 路径统计 题解
I2C [2] - why does IIC need to use open drain output and pull-up resistor bug
面了十多家实习岗位失败的实习面试经历总结
Using streamapi assertion combination and local cache for fuzzy query (nearly 1000 times more efficient than MySQL)
Do you really know binary tree? (Part I)
一文彻底搞懂MySQL基础:B树和B+树的区别
Worthington木瓜蛋白酶特异性和应用
Worthington collagenase raw material
文件I/O
Yx2811 landscape installation driver IC
I2C【2】-IIC为什么需要用开漏输出和上拉电阻bug