#include #include #include #include #include #include #include #include using namespace std; using ll = long long; using pp = pair; using vp = vector; void BFS(vector> G, vector> & dist, int s, int p) { queue que; que.push({s, p}); dist[s][p] = 0; while (!que.empty()) { int v = que.front().first; int p = que.front().second; que.pop(); for (auto nv : G[v][p]) { int x = nv.first;int np = nv.second; if (dist[x][np] == -1) { dist[x][np] = dist[v][p] + 1; que.push({x, np}); } } } } int main() { int N, M;ll K;int S, T; cin >> N >> M >> K >> S >> T; S--;T--; vector> G(N, vector(2)); vector> A(N, vector(N, false)); for (int i = 0;i < M;i++) { int u, v;cin >> u >> v; u--;v--; A[u][v] = true; A[v][u] = true; for (int a = 0;a < 2;a++) { G[u][a].push_back({v, (a+1)%2}); G[v][a].push_back({u, (a+1)%2}); } } vector> dist1(N, vector(2, -1)); auto dist2 = dist1; auto dist3 = dist1; BFS(G, dist1, S, 0); BFS(G, dist2, T, 0); ll P = K%2; if (dist1[T][P] != -1 and dist1[T][P] <= K) { cout <<"Yes" << endl; return 0; } for (int a = 0;a < N;a++) for (int b = 0;b < N;b++) { if (A[a][b]) continue; if (a == b) continue; for (int i = 0;i < 2;i++) for (int j = 0;j < 2;j++) { // a to b if (dist1[a][i] != -1 and dist2[b][j] != -1) { ll nd = dist1[a][i] + dist2[b][j] + 1; ll NP = (i + j + 1) % 2; if (NP == P and nd <= K) { cout <<"Yes" << endl; return 0; } } if (b == T) { if (dist1[a][i] != -1) { ll nd = dist1[a][i] + 1; ll NP = (i+1)%2; if (NP == P and nd <= K) { cout <<"Yes" << endl; return 0; } } } } } cout <<"No" << endl; }