20pts
查看原帖
20pts
930686
Forge_Unique楼主2024/4/3 10:50
#include<map>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define _ 0
#define int long long
#define pii pair <int,int>
#define fx first
#define fy second
using namespace std;
const int N = 10010,M = 200010;
int h[N][10],idx[N];
int u[M],v[M];
int n,m,s,t,ans = 1e9;
bool st[N];
void add(int x,int y){
	h[x][idx[x]] = y;
	idx[x]++;
}
void dfs(int x,int u){
	if(st[x]){
		return ;
	} else {
		st[x] = true;
	}
	if(x == t){
		ans = min(ans,u);
	}
	for(int i = 0;i < idx[x];i++){
		dfs(h[x][i],u + 1);
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	memset(st,false,sizeof(st));
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		cin >> u[i] >> v[i];
		add(u[i],v[i]);
	}
	cin >> s >> t;
	dfs(s,0);
	if(ans == 1e9){
		cout << -1;
	} else {
		cout << ans;
	}
	return ~~(0^_^0);
	cout << "114514";
}

20pts

2024/4/3 10:50
加载中...