/* -*- coding: utf-8 -*- * * 3291.cc: No.3291 K-step Navigation - yukicoder */ #include #include #include #include using namespace std; /* constant */ const int MAX_N = 2000; const int MAX_N2 = MAX_N * 2; /* typedef */ using ll = long long; using vi = vector; using qi = queue; /* global variables */ bool es[MAX_N][MAX_N]; vi nbrs[MAX_N]; int sds[MAX_N2], tds[MAX_N2]; /* subroutines */ void bfs(int n, int st, int ds[]) { fill(ds, ds + n * 2, -1); ds[st << 1] = 0; qi q; q.push(st << 1); while (! q.empty()) { int u = q.front(); q.pop(); int ux = (u >> 1), up = (u & 1); int vd = ds[u] + 1; for (auto vx: nbrs[ux]) { int v = (vx << 1) | (up ^ 1); if (ds[v] < 0) ds[v] = vd, q.push(v); } } } /* main */ int main() { int n, m, s, t; ll k; scanf("%d%d%lld%d%d", &n, &m, &k, &s, &t); s--, t--; for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); u--, v--; es[u][v] = es[v][u] = true; nbrs[u].push_back(v); nbrs[v].push_back(u); } bfs(n, s, sds); bfs(n, t, tds); int d0 = sds[(t << 1) | (k & 1)]; if (d0 >= 0 && d0 <= k) { puts("Yes"); return 0; } for (int ux = 0; ux < n; ux++) for (int vx = 0; vx < n; vx++) if (ux != vx && ! es[ux][vx]) for (int up = 0; up < 2; up++) for (int vp = 0; vp < 2; vp++) { int u = (ux << 1) | up; int v = (vx << 1) | vp; if (sds[u] >= 0 && tds[v] >= 0 && sds[u] + 1 + tds[v] <= k && (up ^ vp ^ 1) == (k & 1)) { puts("Yes"); //printf(" ux=%d,vx=%d\n", ux + 1, vx + 1); return 0; } } puts("No"); return 0; }