#include<iostream> #include<string> #include<cstring> using namespace std;//dfs int flag; int p[3]; int a[200][200]; void Dfs(int n,int m)//起点,终点 { if (n == m) { flag = 1; return; } for (int i = 0; i < 3; i++) { if (a[n][i] && !p[a[n][i]]) { p[a[n][i]] = 1; Dfs(a[n][i], m); p[a[n][i]] = 0;//??? } } } int main() { int n; int m; while (cin >> n && n != 0) { flag = 0; for (int i = 1; i <=n;i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; } } cin >> m;//代表终点 p[1] = 1;//起点访问过 Dfs(1,m); if (flag == 1) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }