题目分析

if(dis[y]>dis[x]+edge[i].w){
dis[y]=dis[x]+edge[i].w;
ans[y]=ans[x];
}
else if(dis[y]==dis[x]+edge[i].w) ans[y]+=ans[x];


#include<bits/stdc++.h>
#define re register
#define ll long long
using namespace std;
{
ll k=1,sum=0;
char c=getchar();
for(;c<'0' || c>'9';c=getchar()) if(c=='-') k=-1;
for(;c>='0' && c<='9';c=getchar()) sum=sum*10+c-'0';
return sum*k;
}
const int N=2e3+10,E=4e6+10;
int n,e;
struct Edge{
int to,nxt,w;
};
Edge edge[E<<1];
const int MOD=100003;
int dep[N];
int dis[N],ans[N];
bool vis[N];
int awsl[N][N];
struct New{
int x,d;
bool operator<(const New& qwq) const{
return d>qwq.d;
}
};
priority_queue<New> Q;
inline void Add(int x,int y,int w){
edge[++cnt].to=y;
edge[cnt].w=w;
}
inline void Dijkstra(){
memset(dis,0x3f3f3f3f,sizeof(dis));
dis[1]=0;ans[1]=1;
Q.push((New){1,0});
while(!Q.empty()){
New fr=Q.top();Q.pop();
int x=fr.x;
if(vis[x]) continue;
vis[x]=1;
int y=edge[i].to;
if(dis[y]>dis[x]+edge[i].w){
dis[y]=dis[x]+edge[i].w;
ans[y]=ans[x];
Q.push((New){y,dis[y]});
}
else if(dis[y]==dis[x]+edge[i].w) ans[y]+=ans[x];
}
}
}
int main()
{