WA悬关
查看原帖
WA悬关
1234604
rainbow_MMM楼主2025/6/27 19:00
#include <bits/stdc++.h>
using namespace std;
int n,m,a,b;
int v[200005];
vector<int> G[200005];
bool vis[200005];
struct node{
	int x;
	int st;
};
void bfs(int n){
	queue<node> q;
	q.push({n,1});
	while(!q.empty()){
		int x=q.front().x;
		int y=q.front().st;
		q.pop();
		if(x==b){
			cout<<y+v[b]-v[a];
			return ;
		}
		for(int i=0;i<G[x].size();i++){
			if(!vis[G[x][i]]){
				vis[G[x][i]]=1;
				q.push({G[x][i],y+1});
			}
		}
	}
	puts("No solution");
}
int main()
{
	cin>>n>>m>>a>>b;
	for(int i=1;i<=n;i++)cin>>v[i];
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		G[x].push_back(y);
	}
	bfs(a);
	return 0;
}
2025/6/27 19:00
加载中...