文章

37

粉丝

1

获赞

316

访问

9.5k

头像
最短路径条数统计 题解:
P5380 复旦大学2024年机试题
发布于2026年3月5日 15:08
阅读数 300

#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
vector<vector<pair<int,int>>> adj(N);
int dist[N];
int cnt[N];

void dijikstra(int start){
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
	pq.push({0,start});
	dist[start] = 0;
	cnt[start] = 1;
	
	while(!pq.empty()){
		int d = pq.top().first;
		int u = pq.top().second;
		pq.pop();
		
		if(d>dist[u]) continue;
			
		for(auto it : adj[u]){
			int w = it.first;
			int v = it.second;
			
			if(dist[v] > dist[u] + w){
				cnt[v] = (cnt[u])%MOD;
				dist[v] = dist[u] + w;
				pq.push({dist[v],v});
			}
			else if(dist[v] == dist[u] + w){
				cnt[v] = (cnt[v]+cnt[u])%MOD;
			}
		}
	}
	
}



int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n,m,s,t; cin>>n>>m>>s>>t;
	for(int i = 0; i < m;...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发