求助!
查看原帖
求助!
704634
poor_OIer楼主2023/9/4 21:53

Yanglidouguobuliao! \Huge Yang lidouguobuliao !

样例都过不了!

Code:\huge\color{green} Code:

#include<bits/stdc++.h>
#define INF 0x7ffffff
#define mod 100003
using namespace std;
int n,m,head[2000010],vis[1000010],dis[1000010],mst[1000010],cnt;
struct Edge{
	int to,next;
}edge[2000010];
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
inline void addEdge(int u,int v)
{
	cnt++;
	edge[cnt].to=v;
	edge[cnt].next=head[u];
	head[u]=cnt;
}
inline void input()
{
	n=read(),m=read();
	for(int i=1;i<=m;i++)
	{
		int u=read(),v=read();
		addEdge(u,v);
		addEdge(v,u);
	}
}
inline void dijkstra()
{
	dis[1]=0;
	mst[1]=1;
	priority_queue<pair<int,int> > q;
	q.push(make_pair(0,1));
	while(!q.empty())
	{
		int tmp=q.top().second;
		q.pop();
		if(vis[tmp])
			continue;
		vis[tmp]=1;
		for(int i=head[tmp];i;i=edge[i].next)
		{
			int to=edge[i].to;
			if(dis[to]>dis[tmp]+1)
			{
				dis[to]=dis[tmp]+1;
				mst[to]=mst[tmp];
				q.push(make_pair(dis[to],to));
			}
			else if(dis[to]==dis[tmp]+1)
			{
				mst[to]+=mst[tmp];
				mst[to]%=mod;
			}
		}
	}
}
inline void init()
{
	for(int i=1;i<=n;i++)
		vis[i]=0,dis[i]=INF;
}
inline void output()
{
	for(int i=1;i<=n;i++)
		cout<<mst[i]<<endl;
}
int main()
{
	init();
	input();
	dijkstra();
	output();
	return 0;
}

Help!\Huge \color{gold}Help!

2023/9/4 21:53
加载中...