样例炸了求调
查看原帖
样例炸了求调
551630
Lemon_zqp楼主2024/10/16 13:12
#include<bits/stdc++.h>
const int maxn = 1000005;
const int inf = 2147483647;
using namespace std;

int n, m, cnt, head[maxn], to[maxn], dis[maxn], nxt[maxn], mindis[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;
	}
} tmp;

priority_queue<node> q;

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

int main(){
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		int a, b;
		cin >> a >> b;
		add(a, b);
		add(b, a);
	}
	for(int i = 0; i <= n; i++){
		numdis[i] = 1;
	}
	dijkstra();
	for(int i = 1; i <= n; i++){
		cout << numdis[i] << endl;
	}
	return 0;
}
2024/10/16 13:12
加载中...