当前位置:网站首页>Sightseeing - statistics of the number of shortest paths + state transfer + secondary small paths
Sightseeing - statistics of the number of shortest paths + state transfer + secondary small paths
2022-07-03 20:14:00 【Wawa source】
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
#define x first
#define y second
typedef pair<int, int> PII;
const int N = 1010,M = 10010;
vector<PII>g[N];
int n,m,s,t;
int dist[N][2];
int cnt[N][2];
bool st[N][2];
struct node
{
int ver,type,w;
bool operator > (const node &W)const
{
return w>W.w;
}
};
int dij()
{
memset(dist,0x3f,sizeof dist);
memset(cnt,0,sizeof cnt);
memset(st,0,sizeof st);
dist[s][0]=0;cnt[s][0]=1;
priority_queue<node,vector<node>,greater<node> >heap;
heap.push({
s,0,0});
while(heap.size())
{
auto t=heap.top();
heap.pop();
int u=t.ver,type=t.type,distance=t.w;
if(st[u][type])continue;
st[u][type]=true;
for(auto [v,w] : g[u])
{
if(dist[v][0]>distance+w)
{
dist[v][1]=dist[v][0],cnt[v][1]=cnt[v][0];
heap.push({
v,1,dist[v][1]});
dist[v][0]=distance+w,cnt[v][0]=cnt[u][type];
heap.push({
v,0,dist[v][0]});
}
else if(dist[v][0]==distance+w)
{
cnt[v][0]+=cnt[u][type];
}
else if(dist[v][1]>distance+w)
{
dist[v][1]=distance+w,cnt[v][1]=cnt[u][type];
heap.push({
v,1,dist[v][1]});
}
else if(dist[v][1]==distance+w)
{
cnt[v][1]+=cnt[u][type];
}
}
}
int res=cnt[t][0];
if(dist[t][0]==dist[t][1]-1)res+=cnt[t][1];
return res;
}
signed main()
{
int T;
cin>>T;
while(T--)
{
cin>>n>>m;
int a,b,c;
for(int i=1;i<=n;i++)g[i].clear();
for(int i=1;i<=m;i++)
{
cin>>a>>b>>c;
g[a].push_back({
b,c});
}
cin>>s>>t;
cout<<dij()<<endl;
}
}
边栏推荐
- The 29th day of force deduction (DP topic)
- Today's work summary and plan: February 14, 2022
- 2. Template syntax
- Nacos usage of micro services
- Phpexcel import export
- Professional interpretation | how to become an SQL developer
- AI enhanced safety monitoring project [with detailed code]
- Use of aggregate functions
- 6006. Take out the minimum number of magic beans
- Wechat applet quick start (including NPM package use and mobx status management)
猜你喜欢
2.2 integer
Sparse matrix (triple) creation, transpose, traversal, addition, subtraction, multiplication. C implementation
kubernetes集群搭建efk日志收集平台
The 29th day of force deduction (DP topic)
Make a simple text logo with DW
Cesiumjs 2022 ^ source code interpretation [7] - Analysis of the request and loading process of 3dfiles
JMeter plug-in installation
2022 Xinjiang latest construction eight members (standard members) simulated examination questions and answers
2022-06-30 網工進階(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】
It is discussed that the success of Vit lies not in attention. Shiftvit uses the precision of swing transformer to outperform the speed of RESNET
随机推荐
2. Template syntax
How to read the source code [debug and observe the source code]
【leetcode】1027. Longest arithmetic sequence (dynamic programming)
Typora charges, WTF? Still need support
AST (Abstract Syntax Tree)
Test panghu was teaching you how to use the technical code to flirt with girls online on Valentine's Day 520
Unittest framework is basically used
BOC protected tryptophan zinc porphyrin (Zn · TAPP Trp BOC) / copper porphyrin (Cu · TAPP Trp BOC) / cobalt porphyrin (cobalt · TAPP Trp BOC) / iron porphyrin (Fe · TAPP Trp BOC) / Qiyue supply
Geek Daily: the system of monitoring employees' turnover intention has been deeply convinced off the shelves; The meta universe app of wechat and QQ was actively removed from the shelves; IntelliJ pla
Rad+xray vulnerability scanning tool
Bool blind note - score query
Cap and base theory
2.1 use of variables
Strict data sheet of new features of SQLite 3.37.0
App compliance
47. Process lock & process pool & Collaboration
Wargames study notes -- Leviathan
Utilisation de base du cadre unitest
HCIA-USG Security Policy
MySQL learning notes - single table query