死了
查看原帖
死了
551630
Lemon_zqp楼主2024/10/16 14:11
#include<bits/stdc++.h>
#define int long long
const int maxn = 2000005;
const int inf = 2147483647;
using namespace std;

int n, m, cnt, head[maxn], to[maxn], dis[maxn], nxt[maxn], numdis[maxn];
bool vis[maxn];

void add(int u, int v){
	to[++cnt] = v;
	nxt[cnt] = head[u];
	head[u] = cnt;
}

struct node{
	int v, w;
	friend bool operator < (node a, node b){
		return a.w > b.w;
	}
};

priority_queue<node> q;

void dijkstra(){
	for(int i = 1; i <= n; i++){
		dis[i] = inf;
	}
	dis[1] = 0;
	q.push({1, 0});
	while(!q.empty()){
		int u = q.top().v;
		q.pop();
		if(vis[u]) continue;
		vis[u] = true;
		for(int i = head[u]; i; i = nxt[i]){
			if(dis[to[i]] > (long long)dis[u] + 1){
				dis[to[i]] = dis[u] + 1;
				numdis[to[i]] = numdis[u];
				numdis[to[i]] %= 100003;
				q.push({to[i], dis[to[i]]});
			}
			else if(dis[to[i]] == dis[u] + 1){
				numdis[to[i]] += numdis[u];
				numdis[to[i]] %= 100003;
			}
		}
	}
}

signed main(){
//	freopen("P1144_6.in", "r", stdin);
//	freopen("P1144_1.out", "w", stdout);
	scanf("%d%d", &n, &m);
	while(m--){
		int a, b;
		scanf("%d%d", &a, &b);
		add(a, b); 
		add(b, a);
	}
	numdis[1] = 1;
	dijkstra();
	for(int i = 1; i <= n; i++){
		printf("%d\n", numdis[i]);
	}
	return 0;
}
2024/10/16 14:11
加载中...