求助,官方数据能过,HACK数据错5个
查看原帖
求助,官方数据能过,HACK数据错5个
1094797
Myl100313楼主2024/12/15 21:22

有人吗?有人就帮我看看代码。

代码如下:

#include<bits/stdc++.h>
using namespace std;
int m,n;
vector<int> C1[114514],C2[114514];
int num[114514];
queue<int> team;
int dis[114514],dis2[114514];
bool book[114514];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
	    scanf("%d",&num[i]);
	    dis[i]=INT_MAX;
    }
    for(int q=1;q<=m;q++)
    {
    	int x,y,z;
    	scanf("%d%d%d",&x,&y,&z);
    	C1[x].push_back(y);
    	C2[y].push_back(x);
		if(z==2)
		{
			C1[y].push_back(x);
			C2[x].push_back(y);
		} 
	}
	memset(book,false,sizeof book);
	team.push(1);
	book[1]=true;
	while(!team.empty())
	{
		int u=team.front();
		book[u]=false;
		for(int j=0;j<C1[u].size();j++)
		{
			int v=C1[u][j];
			if(dis[u]<dis[v]||num[v]<dis[v])
			{
				dis[v]=min(dis[u],num[v]);
				if(book[v]==false)
				{
					book[v]=true;
					team.push(v);
				}
			}
		}
		team.pop();
	}
	memset(book,false,sizeof book);
	while(!team.empty()) team.pop();
	team.push(n);
	book[n]=true; 
	while(!team.empty())
	{
		int u=team.front();
		book[u]=false;
		for(int j=0;j<C2[u].size();j++)
		{
			int v=C2[u][j];
			if(dis2[u]>dis2[v]||num[v]>dis2[v])
			{
				dis2[v]=max(dis2[u],num[v]);
				if(book[v]==false)
				{
					book[v]=true;
					team.push(v);
				}
			}
		}
		team.pop();
	}
	int ans=INT_MIN;
	for(int i=1;i<=n;i++) ans=max(ans,dis2[i]-dis[i]);
	printf("%d\n",ans);
	return 0;
}

为什么呢?

2024/12/15 21:22
加载中...