当前位置:网站首页>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;
}
}
边栏推荐
- FPGA 学习笔记:Vivado 2019.1 工程创建
- 2.5 conversion of different data types (2)
- Phpstudy set LAN access
- 2022 Xinjiang latest road transportation safety officer simulation examination questions and answers
- Class loading process
- Global and Chinese market of liquid antifreeze 2022-2028: Research Report on technology, participants, trends, market size and share
- Typora charges, WTF? Still need support
- 4. Data splitting of Flink real-time project
- 2.3 other data types
- BOC protected tryptophan porphyrin compound (TAPP Trp BOC) Pink Solid 162.8mg supply - Qiyue supply
猜你喜欢

Upgrade PIP and install Libraries
![Meso tetra [P - (p-n-carbazole benzylidene imino)] phenylporphyrin (tcipp) /eu (tcipp) [pc( α- 2-oc8h17) 4] and euh (tcipp) [pc (a-2-oc8h17) 4] supplied by Qiyue](/img/5b/fc776a1982e24b82984d82be6a016f.jpg)
Meso tetra [P - (p-n-carbazole benzylidene imino)] phenylporphyrin (tcipp) /eu (tcipp) [pc( α- 2-oc8h17) 4] and euh (tcipp) [pc (a-2-oc8h17) 4] supplied by Qiyue

2.7 format output of values

Vscode reports an error according to the go plug-in go get connectex: a connection attempt failed because the connected party did not pro

FPGA learning notes: vivado 2019.1 project creation

Virtual machine installation deepin system

Network security Kali penetration learning how to get started with web penetration how to scan based on nmap

Acquisition and transmission of parameters in automatic testing of JMeter interface

AcWing 1460. Where am i?
![AI enhanced safety monitoring project [with detailed code]](/img/a9/cb93f349229e86cbb05ad196ae9553.jpg)
AI enhanced safety monitoring project [with detailed code]
随机推荐
AcWing 1460. Where am i?
Part 27 supplement (27) buttons of QML basic elements
Blue Bridge Cup: the fourth preliminary - "simulated intelligent irrigation system"
Phpexcel import export
2. Template syntax
11-grom-v2-05-initialization
JMeter plug-in installation
Bool blind note - score query
Plan for the first half of 2022 -- pass the PMP Exam
FAQs for datawhale learning!
IPv6 experiment
What is the difference between a kill process and a close process- What are the differences between kill process and close process?
Parental delegation mechanism
CesiumJS 2022^ 源码解读[7] - 3DTiles 的请求、加载处理流程解析
Point cloud data denoising
FPGA 学习笔记:Vivado 2019.1 工程创建
6. Data agent object Defineproperty method
Make a simple text logo with DW
Microsoft: the 12th generation core processor needs to be upgraded to win11 to give full play to its maximum performance
Wechat applet quick start (including NPM package use and mobx status management)