当前位置:网站首页>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;
}
}
边栏推荐
- MySQL learning notes - single table query
- Promethus
- The simplicity of laravel
- Titles can only be retrieved in PHP via curl - header only retrieval in PHP via curl
- Bright purple crystal meso tetra (4-aminophenyl) porphyrin tapp/tapppt/tappco/tappcd/tappzn/tapppd/tappcu/tappni/tappfe/tappmn metal complex - supplied by Qiyue
- BOC protected tryptophan porphyrin compound (TAPP Trp BOC) Pink Solid 162.8mg supply - Qiyue supply
- Global and Chinese market of speed limiter 2022-2028: Research Report on technology, participants, trends, market size and share
- [raid] [simple DP] mine excavation
- How to set the system volume programmatically- How to programmatically set the system volume?
- Test access criteria
猜你喜欢
Test changes in Devops mode -- learning and thinking
Test panghu was teaching you how to use the technical code to flirt with girls online on Valentine's Day 520
Kubernetes cluster builds efk log collection platform
FPGA learning notes: vivado 2019.1 project creation
Change deepin to Alibaba image source
Explore the internal mechanism of modern browsers (I) (original translation)
FPGA 学习笔记:Vivado 2019.1 工程创建
5- (4-nitrophenyl) - 10,15,20-triphenylporphyrin ntpph2/ntppzn/ntppmn/ntppfe/ntppni/ntppcu/ntppcd/ntppco and other metal complexes
Xctf attack and defense world crypto advanced area best_ rsa
BOC protected phenylalanine zinc porphyrin (Zn · TAPP Phe BOC) / iron porphyrin (Fe · TAPP Phe BOC) / nickel porphyrin (Ni · TAPP Phe BOC) / manganese porphyrin (Mn · TAPP Phe BOC) Qiyue Keke
随机推荐
Strict data sheet of new features of SQLite 3.37.0
Global and Chinese market of high purity copper foil 2022-2028: Research Report on technology, participants, trends, market size and share
4. Data splitting of Flink real-time project
3. Data binding
How to do Taobao full screen rotation code? Taobao rotation tmall full screen rotation code
BOC protected amino acid porphyrins TAPP ala BOC, TAPP Phe BOC, TAPP Trp BOC, Zn · TAPP ala BOC, Zn · TAPP Phe BOC, Zn · TAPP Trp BOC Qiyue
Cap and base theory
BOC protected phenylalanine zinc porphyrin (Zn · TAPP Phe BOC) / iron porphyrin (Fe · TAPP Phe BOC) / nickel porphyrin (Ni · TAPP Phe BOC) / manganese porphyrin (Mn · TAPP Phe BOC) Qiyue Keke
Global and Chinese markets of active matrix LCD 2022-2028: Research Report on technology, participants, trends, market size and share
AST (Abstract Syntax Tree)
Bool blind note - score query
Explore the internal mechanism of modern browsers (I) (original translation)
Global and Chinese market of electrolyte analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
Promethus
Microservice knowledge sorting - search technology and automatic deployment technology
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
MySQL dump - exclude some table data - MySQL dump - exclude some table data
Global and Chinese markets of cast iron diaphragm valves 2022-2028: Research Report on technology, participants, trends, market size and share
Virtual machine installation deepin system
Get log4net log file in C - get log4net log file in C